Python Forum
Graphics Formatting - X-axis Notation and Annotations - Matplotlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Graphics Formatting - X-axis Notation and Annotations - Matplotlib
#1
Distinguished colleagues, good morning.

I am working on building a graph using matplotlib and I am facing some difficulties.

How can I leave the X-axis in the base ten format raised to an exponent? For example, 10³. The graph places a scale factor of 1 and 7 on the right side of the axis. I would like, for each value of the graph, to have the decimal base accompanying it. For example, 2.10².

Regarding the annotations added at the bottom right of the figure. How can I put a rectangle around these annotations? And yet, how can I leave the text centering inside that rectangle?

Thank you so much for your attention and follow the code below.

from matplotlib import pyplot as plt
import numpy as np
import pandas as pd

x=pd.read_excel(r"C:\pythonprogramas\graficosdoutorado\experimental.xlsx", 'Planilha4')

fig = plt.subplots(figsize = (20,10))

plt.xlabel('$\mathbf{Ra_{L_{P}}}$', fontsize=18, fontweight='bold')
plt.ylabel('$\mathbf{\overline{N u}_{L_{P}}}$', fontsize=18, fontweight='bold')

plt.scatter(x['RaE'], x['NuE'], marker='x', label='Experimental')
plt.errorbar(x['RaE'],x['NuE'],yerr=x['ErroE'], color='k', fmt=' ', capsize=5)

plt.scatter(x['RaN'], x['NuN'], color='#CC6600', marker='s', label='Numérica')

x5 = np.arange(2E6,1.2E7,100000)
plt.plot(x5, 1.152347*(x5**0.200198),'--', color='k')

plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc='lower left', ncol=3, fontsize=18, mode="expand", borderaxespad=0.)

plt.annotate('$\overline{N u}_{L_{P}}=1.152347 \cdot Ra_{L_{P}}^{0,200198}$ \n $\mathrm{R^{2}}=0,952$', size=20, xy=(1.05E7, 29), xytext=(8E6, 21))

plt.ticklabel_format(axis="x", style="sci", scilimits=(0,0))

plt.xlim(2E6, 1.1E7)

#plt.xticks(np.arange(2E6, 1.15E7, 5E5),rotation=90)

plt.yticks(np.arange(18, 33, 1))

plt.savefig("C:/pythonprogramas/graficosdoutorado/imagens/graficoExp4.png", bbox_inches='tight', pad_inches = 0)
plt.show()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Forcing matplotlib to NOT use scientific notation when graphing sawtooth500 4 428 Mar-25-2024, 03:00 AM
Last Post: sawtooth500
  ''.join and start:stop:step notation for lists ringgeest11 2 2,457 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  issue with converting a scientific notation to standard notation thomaswfirth 4 1,404 Jun-06-2023, 06:06 PM
Last Post: rajeshgk
  matplotlib x-axis text move bottom upward jacklee26 3 1,018 May-31-2023, 04:28 AM
Last Post: jacklee26
  notation MCL169 8 1,518 Apr-14-2023, 12:06 PM
Last Post: MCL169
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,099 Dec-06-2022, 11:09 AM
Last Post: mg24
  x-axis labels with Matplotlib Mark17 8 2,269 Mar-23-2022, 06:10 PM
Last Post: Mark17
  How to make x-axis readable with matplotlib Mark17 7 3,975 Mar-01-2022, 04:30 PM
Last Post: DPaul
  matplotlib x axis range goes over the set range Pedroski55 5 3,257 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 4,431 Sep-14-2021, 08:29 AM
Last Post: hobbyist

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020