| Contents | Index |
To control the presence and appearance of grid lines on a graph,
use the Property Editor, one of the plotting tools
. For details, see The
Property Editor in the MATLAB Graphics documentation.
grid on
grid off
grid
grid(axes_handle,...)
grid minor
The grid function turns the current axes' grid lines on and off.
grid on adds major grid lines to the current axes.
grid off removes major and minor grid lines from the current axes.
grid toggles the major grid visibility state.
grid(axes_handle,...) uses the axes specified by axes_handle instead of the current axes.
grid sets the XGrid, YGrid, and ZGrid properties of the axes.
grid minor sets the XMinorGrid, YMinorGrid, and ZMinorGrid properties of the axes.
You can set the grid lines for just one axis using the set command and the individual property. For example,
set(axes_handle,'XGrid','on')
turns on only x-axis grid lines.
You can set grid line width with the axes LineWidth property.
By default, the number of grid lines changes when you resize a figure. To prevent this and keep grids the same at any size, set the XTickMode or YTickMode axes properties to 'manual':
set(axes_handle,'XTickMode','manual') set(axes_handle,'YTickMode','manual')
To customize the locations of ticks along an axis, set the axes XTick, YTick, and ZTick properties. For minor ticks, use the XMinorTick, YMinorTick, and ZTick properties.
Create multiple plots within a single figure and manipulate their grid visibility using the grid function:
figure
subplot(2,2,1)
plot(rand(1,20))
title('grid off')
subplot(2,2,2)
plot(rand(1,20))
grid on
title('grid on')
subplot(2,2,[3 4])
plot(rand(1,20))
grid(gca,'minor')
title('grid minor')

You can also use the following code to control grids on a per-axis basis:
set(axh,'XGrid','on','YGrid','on','ZGrid','on')

Explore how to use MATLAB to make advancements in engineering and science.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |