grid

Display or hide axes grid lines

Syntax

• `grid on` example
• `grid off` example
• `grid`

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. 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, `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') ```

collapse all