Sometimes, we want to plot logarithmic axes with matplotlib in Python.
In this article, we’ll look at how to plot logarithmic axes with matplotlib in Python.
How to plot logarithmic axes with matplotlib in Python?
To plot logarithmic axes with matplotlib in Python, we can use the set_yscale
method.
For instance, we write
import pylab
import matplotlib.pyplot as plt
a = [pow(10, i) for i in range(10)]
fig = plt.figure()
ax = fig.add_subplot(2, 1, 1)
line, = ax.plot(a, color='blue', lw=2)
ax.set_yscale('log')
pylab.show()
to call set_yscale
with 'log'
to make the y-axis a logarithmic axis.
We lot the values in list a
with with the lot.
Conclusion
To plot logarithmic axes with matplotlib in Python, we can use the set_yscale
method.