Table of contents
1. Parameters
plt.grid(b, which, axis, color, linestyle, linewidth, which, **kwargs)
- b : Boolean value. It means whether to display grid lines or not.
- axis : The values are 'both', 'x', 'y'. Just want to draw the grid lines in which direction.
- color : Needless to say, this is to set the color of the grid lines. Or you can directly use c instead of color.
- linestyle : You can also use ls instead of linestyle to set the style of the grid lines, which are continuous solid lines, dashed lines or other different lines. Includes: '-' , '--' , '-.' , ':' , 'None' , ' ', ''.
- linewidth : Sets the width of the grid lines.
- alpha: Mesh transparency.
- which : Whether to draw the grid with the major scale or the minor scale, if the major and minor grids are set. Values are 'major', 'minor', 'both'.
2. Examples
import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.text(1, 1.5, 'First')
plt.text(2, 4.5, 'Second')
plt.grid(b=True, linestyle="--", alpha=0.5,axis="both")
plt.show()