grid

Turns the axes grid lines on or off.

Category: Graphics > Formatting and Annotation

Syntax

grid on

Shows the major grid lines of the current axes.

grid off

Hides the grid lines.

grid

Toggles the grid between on and off.

grid minor

Toggles the minor grid lines, which sit between the major ticks.

Description

The grid lines follow the axis ticks, so they change when the ticks change. Grid state is stored on the axes, in the properties XGrid, YGrid and ZGrid, together with XMinorGrid and its relatives for the minor lines.

Called with no argument, grid flips the current state, which makes a script that runs twice show the opposite grid the second time. Prefer grid on or grid off when the outcome should be fixed.

Input arguments

ax
Optional first argument: the axes to change instead of the current axes.

Example

Grid with minor lines

x = linspace(0, 4*pi, 100);
plot(x, sin(x))
grid on
grid minor
ax = gca;
ax.XGrid
ax.XMinorGrid
Output
ans = 'on'
ans = 'off'

See also

box xticks yticks axis hold