Qu

grid

Builtin index · Plotting

grid on|off / grid minor [off] (bare command)

Input: bare command · Output: no output

What it is

on/off toggles major gridlines. minor/minor off independently toggles dotted minor gridlines (MATLAB allows minor grid without major grid too, so this never forces major grid on). Calling grid(...) as a function is accepted but is a no-op — only the bare command form actually changes anything.

Overloads

2 forms. Each carries its own inputs, outputs and worked example — pick the tab for the one you are calling.

CodeInputOutputDescription
grid on|off / grid minor [off] (bare command)
bare command —not documented yet
no outputgrid off (bare) is the real toggle — it actually removes the panel's gridlines.

Examples

Written for this form and run by the build -- the output below is what the engine actually produced.

t = linspace(0, 1, 50)
plot(t, sin(t))
grid off
output
· plot: figure 6 (50 points)
10−279 10−248 10−217 10−186 10−155 10−124 10−93 10−62 10−31 100 -100 -50 0 50 100 (0, 1.9) 6 dB = 1 bit sin(x) cos(x) sin(x)
CodeInputOutputDescription
grid on|off / grid minor [off] (bare command)
bare command —not documented yet
no outputgrid(...) called with parentheses, as a function, is accepted so a MATLAB-style script still parses — but it changes nothing. Calling it after grid off does not turn the grid back on; the gridlines stay off, exactly as grid off left them.

Examples

Written for this form and run by the build -- the output below is what the engine actually produced.

t = linspace(0, 1, 50)
plot(t, sin(t))
grid off
grid()   # no-op -- gridlines stay off, not re-enabled

output
· plot: figure 7 (50 points)
10−279 10−248 10−217 10−186 10−155 10−124 10−93 10−62 10−31 100 -100 -50 0 50 100 (0, 1.9) 6 dB = 1 bit sin(x) cos(x) sin(x)

These figure/axes calls are meant to be composed, not used one at a time, so here is a single panel exercising most of the row above: it renames the tick positions to words instead of numbers on both axes, swaps the figure's font and background, turns on the (currently non-drawing) colormap/colorbar pair, and explicitly restates grid/box/scale even though they are already at their defaults, to show that calling them is always safe. Run it and look at the labels — "start"/"mid"/"end" and "low"/"zero"/"high" should sit exactly where 0, 0.5, 1 and -1, 0, 1 used to, against a warm off-white page instead of pure white:

figure()
t = linspace(0, 1, 200)
plot(t, sin(2 * pi * 5 * t))
xticks([0, 0.5, 1])
xticklabels("start", "mid", "end")
yticks([-1, 0, 1])
yticklabels("low", "zero", "high")
fontfamily("sans")
fontsize(tick = 10, label = 12, title = 14)
figure_background("#f7f7f7")
colormap("viridis")
colorbar()
grid()
box()
subplot(1, 1, 1)
xscale("linear")
yscale("linear")
title("Styled panel")
output
· plot: figure 8 (200 points)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 Styled panel

How it works

grid on/grid off toggles the major gridlines; grid minor/grid minor off toggles dotted minor gridlines independently (MATLAB allows minor grid without major grid too, so this doesn't force show_grid on).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.