MATLAB Examples

Change Grid Line Style

This example shows how to change the grid line style using the GridLineStyle and MinorGridLineStyle axes properties. Line style options are a solid line, '-', a dotted line, ':', a dashed line, '--', and a dash-dotted line, '-.'.

Create a line plot and display the major and minor grid lines. Major grid lines align with the tick marks.

x = -10:10;
y = x.^2;
grid on
grid minor

Specify a solid line for all the grid lines. Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the docid:matlab_ref.f67-432995 function instead.

ax = gca;
ax.GridLineStyle = '-';
ax.MinorGridLineStyle = '-';