# Documentation

### This is machine translation

Translated by
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

• ``grid on``
example
• ``grid off``
example
• ``grid``
• ``grid minor``
example
• ``grid(ax,___)``
example

## 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 vectors, for example, `grid(ax,'on')`, `grid(ax,'off')`, and `grid(ax,'minor')`.```

## Examples

collapse all

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.

```grid(ax1,'on') ```

collapse all