Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# grid

Grid lines for 2-D and 3-D plots

## Syntax

grid on
grid off
grid
grid minor
grid(axes_handle,...)

## Description

grid on adds major grid lines to the current axes.

grid off removes all grid lines from the current axes.

grid toggles the visibility of the major grid lines of the current axes.

grid minor toggles the visibility of the minor grid lines of the current axes.

grid(axes_handle,...) uses the axes specified by axes_handle instead of the current axes.

## Examples

expand all

### Display Grid Lines

Display the grid lines for a sine plot.

```x = linspace(0,10);
y = sin(x);

figure
plot(x,y);
grid on;
```

### Remove Grid Lines

Create a surface plot of the peaks function.

```figure
surf(peaks);
```

Remove the grid lines from the surface plot.

```grid off
```

### Display Major and Minor Grid Lines

Define a vector of random numbers.

```rng(0,'twister');
randnumbers = rand(1,20);
```

Plot the vector. Display the major and minor grid lines on the graph.

```figure
plot(randnumbers)
grid on
grid minor
```

expand all

### Algorithms

Some axes properties control the axes grid lines. For more information on axes properties see Axes Properties.

grid sets the XGrid, YGrid, and ZGrid properties of the axes.

To control the major grid line visibility separately for each axis direction set the XGrid, YGrid, and ZGrid axes properties. These properties can be set to on or off.

```axh = gca;
set(axh,'XGrid','on')
set(axh,'ZGrid','off')```

grid minor sets the XMinorGrid, YMinorGrid, and ZMinorGrid properties of the axes.

To control the minor grid line visibility separately for each axis direction set the XMinorGrid, YMinorGrid, and ZMinorGrid axes properties. These properties can be set to on or off.

```axh = gca;
set(axh,'XMinorGrid','on')
```

To change the grid line width, set the LineWidth axes property.

```axh = gca;
set(axh,'LineWidth',2);```

By default, the number of grid lines changes when you resize a figure. To keep the same number of grid lines for any figure size, set the XTickMode, YTickMode, or ZTickMode axes properties to 'manual'.

```axh = gca;
set(axh,'XTickMode','manual');```

To customize the locations of the tick marks along an axis, set the XTick, YTick, and ZTick axes properties.

```axh = gca;
set(axh,'XTick',[0:5:50]);```

To turn on and off the display of the minor tick marks along an axis, set the XMinorTick, YMinorTick, and ZMinorTick properties to on or off.

```axh = gca;
set(axh,'XMinorTick','on')```