matplotlib.pyplot.grid — Matplotlib 3.10.3 documentation (original) (raw)

matplotlib.pyplot.grid(visible=None, which='major', axis='both', **kwargs)[source]#

Configure the grid lines.

Parameters:

visiblebool or None, optional

Whether to show the grid lines. If any kwargs are supplied, it is assumed you want the grid on and visible will be set to True.

If visible is None and there are no kwargs, this toggles the visibility of the lines.

which{'major', 'minor', 'both'}, optional

The grid lines to apply the changes on.

axis{'both', 'x', 'y'}, optional

The axis to apply the changes on.

**kwargsLine2D properties

Define the line properties of the grid, e.g.:

grid(color='r', linestyle='-', linewidth=2)

Valid keyword arguments are:

Notes

The axis is drawn as a unit, so the effective zorder for drawing the grid is determined by the zorder of each axis, not by the zorder of theLine2D objects comprising the grid. Therefore, to set grid zorder, use set_axisbelow or, for more control, call theset_zorder method of each axis.

Examples using matplotlib.pyplot.grid#