Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

grid

Display or hide axes grid lines

Syntax

Description

example

grid on displays the major grid lines for the current axes. Major grid lines extend from each tick mark.

example

grid off removes all grid lines from the current axes.

grid toggles the visibility of the major grid lines.

example

grid minor toggles the visibility of the minor grid lines. Minor grid lines lie between the tick marks.

example

grid(ax,___) uses the axes defined by ax instead of the current axes (gca). Specify ax as a scalar axes object or polar axes object. Specify ax as the first input argument. You can specify additional input arguments from the previous syntaxes. Use single quotes around input arguments that are character strings, for example, grid(ax,'on'), grid(ax,'off'), and grid(ax,'minor').

Examples

collapse all

Display Grid Lines

Display the grid lines for a sine plot.

x = linspace(0,10);
y = sin(x);
plot(x,y)
grid on

Remove Grid Lines

Create a surface plot and remove the grid lines.

[X,Y,Z] = peaks;
surf(X,Y,Z)
grid off

Display Major and Minor Grid Lines

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.

Display Grid Lines on Specific Axes

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.

grid(ax1,'on')

More About

collapse all

Tips

  • To turn on or off grid lines for each axis direction separately, you must set the axes properties individually. The grid function controls all major and minor grid lines together, setting the corresponding axes properties to either 'on' or 'off'.

  • 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. For a full list, see Axes Properties.

    Axes PropertyDescription
    XTick, YTick, ZTickLocation of tick marks and major grid lines for each axis direction
    XGrid, YGrid, ZGridDisplay of major grid lines for each axis direction
    XMinorGrid, YMinorGrid, ZMinorGridDisplay of minor grid lines for each axis direction
    LineWidthLine width of grid lines, axes box outline, and tick marks
    GridLineStyleMajor grid line style
    MinorGridLineStyleMinor grid line style
    GridColorMajor grid line color
    MinorGridColorMinor grid line color
    GridAlphaMajor grid line transparency
    MinorGridAlphaMinor grid line transparency
    LayerLocation of grid lines with respect to the plotted data

  • Some polar axes properties affect the appearance of the grid lines. This table lists a subset of polar axes properties related to the outline. For a full list, see Polar Axes Properties.

    Axes PropertyDescription
    ThetaTick, RTickLocation of tick marks and major grid lines for each axis direction
    ThetaGrid, RGridDisplay of major grid lines for each axis direction
    ThetaMinorGrid, RMinorGridDisplay of minor grid lines for each axis direction
    LineWidthWidth of outline, tick marks, and grid lines
    GridLineStyleMajor grid line style
    MinorGridLineStyleMinor grid line style
    GridColorMajor grid line color
    MinorGridColorMinor grid line color
    GridAlphaMajor grid line transparency
    MinorGridAlphaMinor grid line transparency
    LayerLocation of grid lines with respect to the plotted data

See Also

| | | | |

Introduced before R2006a

Was this topic helpful?