Is there a simple way to make matplotlib not show the powers of ten in a log plot, and instead just show the numbers? I.e., instead of [10^1, 10^2, 10^3]
display [10, 100, 1000]
? I don't want to change the tickmark locations, just want to get rid of the powers of ten.
This is what I currently have:
I can change the labels themselves via xticks
, however I then get mismatching fonts or sizes for the y tick labels. I am using TeX for this text. I've tried the following:
xx, locs = xticks()
ll = [r'\rm{%s}' % str(a) for a in xx]
xticks(xx, ll)
This gives the following result:
In this particular case, I could use the same LaTeX roman font, but the sizes and looks are different to those in the y axis. Plus, if I used a different LaTeX font in matplotlib this is going to be problematic.
Is there a more flexible way of switching off the power of ten notation?
To remove scientific notation from a matplotlib log-log plot, we can use ax. xaxis.
How to prevent numbers being changed to exponential form in Python Matplotlib? Using style='plain' in the ticklabel_format() method, we can restrict the value being changed into exponential form.
show() and plt. draw() are unnecessary and / or blocking in one way or the other.
The antialiased keyword argument controls whether or not a particular matplotlib artist (e.g. line, polygon, etc) is drawn with antialising or not. Non-antialiased plotting will be faster, so if you're plotting a large amount of data, it can be worthwhile to turn it off.
In python, matplotlib provides a function loglog that makes the plot with log scaling on both of the axis (x-axis and y-axis). matplotlib.pyplot.loglog (x, y [, linewidth, color, basex, basey, ...]) x specifies the x-axis values to be plotted.
Matplotlib handles the negative values for the log scaled axis of the graph by specifying the arguments nonposx and nonposy for the x-axis and y-axis respectively. We can specify the value ‘mask’ or ‘clip’ to the arguments nonposx and nonposy.
In python, matplotlib provides a function loglog that makes the plot with log scaling on both of the axis (x-axis and y-axis). matplotlib.pyplot.loglog (x, y [, linewidth, color, basex, basey, ...])
All of the concepts and parameters of plot can be used here as well. The additional parameters base, subs and nonpositive control the x/y-axis properties. They are just forwarded to Axes.set_xscale and Axes.set_yscale. To use different properties on the x-axis and the y-axis, use e.g. ax.set_xscale ("log", base=10); ax.set_yscale ("log", base=2).
Use a ScalarFormatter
:
from matplotlib import rc
rc('text', usetex=True)
rc('font', size=20)
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter
fig = plt.figure(figsize=(10, 6))
ax = fig.add_subplot(111)
ax.semilogx(range(100))
ax.xaxis.set_major_formatter(ScalarFormatter())
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With