Make a note because I will forget it when I want to use it. How to display log (logarithmic) scale and grid (scale line) in matplotlib.
First, import matplotlib
import matplotlib.pyplot as plt
Specify yscale as'log' to make the y-axis a logscale. If you want the x-axis to be the log scale, use plt.xscale ('log')
.
plt.plot([10,20,30],[10,100,1000],marker='^')
plt.yscale('log')
plt.show()
Specify plt.grid ()
to display the grid. The'major'and'minor' of which =
are the main scale line and the auxiliary scale line, respectively. You can also specify the color and line type with color
and linestyle
.
plt.plot([10,20,30],[10,100,1000],marker='^')
plt.yscale('log')
plt.grid(which='major',color='black',linestyle='-')
plt.grid(which='minor',color='black',linestyle='-')
plt.show()
Recommended Posts