Display or hide axes grid lines
grid displays the
major grid lines for the current axes. Major grid lines extend from
each tick mark.
grid removes all
grid lines from the current axes.
grid toggles the visibility of the major
the visibility of the minor grid lines. Minor grid lines lie between
the tick marks.
the axes defined by
ax instead of the current axes
a scalar axes object. You can specify an axes with any of the input
arguments in the previous syntaxes. Use single quotes around input
arguments that are character strings, for example,
Display the grid lines for a sine plot.
x = linspace(0,10); y = sin(x); plot(x,y) grid on
Create a surface plot and remove the grid lines.
[X,Y,Z] = peaks; surf(X,Y,Z) grid off
Display the major and minor grid lines for a sine plot.
x = linspace(0,10); y = sin(x); plot(x,y) grid on grid minor
By default, major grid lines use a solid line style and align with the tick marks. Minor grid lines use a dotted line style and lie between the tick marks.
Create a figure with two subplots and plot a sine wave in each one.
x = linspace(0,10); y = sin(x); ax1 = subplot(2,1,1); plot(x,y) y2 = sin(3*x); ax2 = subplot(2,1,2); plot(x,y2)
Display the grid lines on the upper subplot.
Some axes properties affect the appearance of the grid lines. By changing property values, you can modify the appearance. This table lists a subset of axes properties related to the grid.
|Location of tick marks and major grid lines for each axis direction|
|Display of major grid lines for each axis direction|
|Display of minor grid lines for each axis direction|
|Line width of grid lines, axes box outline, and tick marks|
|Major grid line style|
|Minor grid line style|
|Major grid line color|
|Minor grid line color|
|Major grid line transparency|
|Minor grid line transparency|
|Location of grid lines with respect to the plotted data|
For a full list, see Axes Properties.
To turn on or off grid lines for each axis direction
separately, you must set the axes properties individually. The
controls all major and minor grid lines together, setting the corresponding
axes properties to either