I have vales with very small difference like... 0.000001. I want to visualize them on logarithmic scale. I am wondering how to do it in matplotlib.
Thanks a lot
pyplot library can be used to change the y-axis or x-axis scale to logarithmic respectively. The method yscale() or xscale() takes a single value as a parameter which is the type of conversion of the scale, to convert axes to logarithmic scale we pass the “log” keyword or the matplotlib. scale.
To change the range of X and Y axes, we can use xlim() and ylim() methods.
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axis
Simply add the keyword argument log=True
Or, in an example:
from matplotlib import pyplot
import math
pyplot.plot([x for x in range(100)],[math.exp(y) for y in range(100)] )
pyplot.xlabel('arbitrary')
pyplot.ylabel('arbitrary')
pyplot.title('arbitrary')
#pyplot.xscale('log')
pyplot.yscale('log')
pyplot.show()
Since all other answers only mention the global pyplot.xscale("log")
approach: You can also set it per axis, but then the syntax is:
ax.set_yscale("log")
You can use this piece of code:
import matplotlib.pyplot
# to set x-axis to logscale
matplotlib.pyplot.xscale('log')
# to set y-axis to logscale
matplotlib.pyplot.yscale('log')
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