[PYTHON] matplotlib log scale display and grid display

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.

environment

Preparation

First, import matplotlib

import matplotlib.pyplot as plt

Log scale display

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()

figure_1.png

Grid display

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()

figure_.png

Recommended Posts

matplotlib log scale display and grid display
Grid display of double plots (left and right vertical axes) (matplotlib)
Install matplotlib and display graph on Jupyter Notebook
matplotlib this and that
[Python] Read the csv file and display the figure with matplotlib
Japanese display of matplotlib, seaborn
NumPy and matplotlib environment construction
Real-time graph display by matplotlib