grid — Toggle axes grid lines in MATLAB and RunMat plotting.
grid controls visibility of major and minor axes grid lines on the active axes or subplot. Command forms such as grid on, grid off, grid minor, and toggle behavior follow MATLAB semantics.
Syntax
enabled = grid()
enabled = grid(mode)Inputs
mode- Type
StringScalar- Required
- No
- Description
- Grid mode token ('on'|'off'|'minor').
Returns
enabled- Type
LogicalArray- Description
- Grid enabled state after command execution.
Errors
RunMat:grid:InvalidArgument- When
- Grid mode argument is unsupported.
- Message
grid: invalid argument
RunMat:grid:TooManyOutputs- When
- More than one output is requested.
- Message
grid: at most one output is supported
Behavior
grid on enables grid lines on the current axes.
grid off disables major and minor grid lines on the current axes.
grid minor toggles minor grid lines without changing the major grid state.
Calling grid with no argument toggles the major grid state.
Grid visibility is subplot-local and does not spill into other axes automatically.
An assigned logical state/success result is a RunMat extension. MATLAB compatibility mode allows command calls but rejects an explicitly requested result before changing state.
Placement and display
These commands update shared graphics state and may notify figure observers. Numeric array acceleration remains with the original plotting/rendering pipeline; the commands do not launch array-provider kernels. Graphics display requires a browser graphics host or a desktop graphics host.
Control arguments must already be host values. Unsupported resident controls reject without provider downloads; existing resident plot buffers stay owned by their plotting/rendering paths. Invalid syntax and excess output requests are checked before creating or changing graphics state.
Examples
Enable grid lines on a simple line chart
plot(1:5, [1 4 2 5 3]);
grid on;Toggle minor grid lines on the current axes
plot(1:10,sin(1:10)); grid off; grid minor;Toggle grid lines in one subplot only
ax1 = subplot(1,2,1); plot(1:5,1:5); grid off;
ax2 = subplot(1,2,2); plot(1:5,[5 4 3 2 1]); grid on;Using grid with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how grid changes the result.
Run a small grid example, explain the result, then change one input and compare the output.
FAQ
Does RunMat support minor grid lines?⌄
Yes. Use grid minor or grid('minor') to toggle minor grid lines on the active axes. grid off disables both major and minor grid lines.
Can I style the grid line color or width?⌄
RunMat currently exposes major and minor grid visibility through axes state. GridColor and grid line-width setters are not supported by this property path; get(gca) lists the properties that are available.
Does grid state carry across subplots?⌄
No. Grid visibility is subplot-local. Calling grid on in one panel doesn't turn it on in others — you need to enable it explicitly in each subplot where you want grid lines.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · autumn · axes · barh · bone · caxis · cla · clf · clim · colorcube · colororder · cool · copper · copyobj · cylinder · daspect · datacursormode · dataTipTextRow · drawnow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · gray · groot · hgload · hgsave · hidden · histogram2 · hold · hot · inferno · isgraphics · ishandle · jet · line · lines · linkaxes · magma · openfig · opengl · pan · parula · patch · pink · plasma · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · spring · stackedplot · subtitle · summer · suptitle · text · textscatter · textscatter3 · triplot · turbo · viridis · waitbar · winter · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
More plotting resources
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.