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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
mode | StringScalar | No | "toggle" | Grid mode token ('on'|'off'|'minor'). |
Returns
| Name | Type | Description |
|---|---|---|
enabled | LogicalArray | Grid enabled state after command execution. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:grid:InvalidArgument | Grid mode argument is unsupported. | grid: invalid argument |
How grid works
grid onenables grid lines on the current axes.grid offdisables major and minor grid lines on the current axes.grid minortoggles minor grid lines without changing the major grid state.- Calling
gridwith no argument toggles the major grid state. - Grid visibility is subplot-local and does not spill into other axes automatically.
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 minor;Toggle grid lines in one subplot only
subplot(1, 2, 1);
plot(1:5, 1:5);
grid off;
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?⌄
Grid styling is tied to axes properties. You can adjust the grid appearance through the axes handle with set(gca, 'GridColor', [0.5 0.5 0.5]) and related properties when the axes property path supports them. Check get(gca) to see what's currently exposed.
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
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how grid is executed, line by line, in Rust.
- View the source for grid in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.