Skill Tracer
Skills › Scientific Agent Skills › matlab › graphics-visualization.md

graphics-visualization.md

183 lines · skills/matlab/references/graphics-visualization.md at 5f2bc03

Open on GitHub
1# Graphics and Export
2
3This reference targets MATLAB R2026a. Rendering and property support differ in
4GNU Octave and across MATLAB releases/platforms.
5

Graphics and Export

This reference targets MATLAB R2026a. Rendering and property support differ in GNU Octave and across MATLAB releases/platforms.

Raw lines 1 to 5
6## Build figures with explicit ownership
7
8Use handles instead of relying on `gcf`/`gca` in reusable code:
9
10```matlab
11fig = figure(Color="white");
12layout = tiledlayout(fig, 2, 1, ...
13 TileSpacing="compact", ...
14 Padding="compact");
16ax1 = nexttile(layout);
17plot(ax1, time, signal, LineWidth=1.5);
18xlabel(ax1, "Time (s)");
19ylabel(ax1, "Amplitude (V)");
20title(ax1, "Measured signal");
21grid(ax1, "on");
23ax2 = nexttile(layout);
24histogram(ax2, residual, Normalization="pdf");
25xlabel(ax2, "Residual (V)");
26ylabel(ax2, "Density");
27```
29Explicit handles make tests, nested layouts, apps, and exports predictable.
30Set limits, aspect ratio, color limits, and view deliberately when comparison
31across figures matters.

Build figures with explicit ownership

Use handles instead of relying on gcf/gca in reusable code:

fig = figure(Color="white");
layout = tiledlayout(fig, 2, 1, ...
    TileSpacing="compact", ...
    Padding="compact");

ax1 = nexttile(layout);
plot(ax1, time, signal, LineWidth=1.5);
xlabel(ax1, "Time (s)");
ylabel(ax1, "Amplitude (V)");
title(ax1, "Measured signal");
grid(ax1, "on");

ax2 = nexttile(layout);
histogram(ax2, residual, Normalization="pdf");
xlabel(ax2, "Residual (V)");
ylabel(ax2, "Density");

Explicit handles make tests, nested layouts, apps, and exports predictable. Set limits, aspect ratio, color limits, and view deliberately when comparison across figures matters.

Raw lines 6 to 32
33## Scientific communication checklist
35- Include quantities and units in labels.
36- State transformations, normalization, aggregation, and uncertainty.
37- Use colorblind-aware, perceptually ordered palettes; do not use color alone
38 for categories.
39- Keep data and annotations distinguishable in grayscale when required.
40- Match marker/line width, font size, and panel size to final publication size.
41- Avoid misleading axis truncation or 3-D effects.
42- Set deterministic sorting/group order before plotting categorical data.
43- Add alternative text/caption information in the surrounding document.
44- Inspect embedded raster content even when the container format is vector.
46Graphics functions can belong to separate products. For example, basic
47`plot`, `scatter`, `histogram`, `imagesc`, `surf`, and `tiledlayout` are base
48MATLAB, while domain-specific statistical, mapping, image, signal, or medical
49visualizations can require named toolboxes.

Scientific communication checklist

  • Include quantities and units in labels.
  • State transformations, normalization, aggregation, and uncertainty.
  • Use colorblind-aware, perceptually ordered palettes; do not use color alone for categories.
  • Keep data and annotations distinguishable in grayscale when required.
  • Match marker/line width, font size, and panel size to final publication size.
  • Avoid misleading axis truncation or 3-D effects.
  • Set deterministic sorting/group order before plotting categorical data.
  • Add alternative text/caption information in the surrounding document.
  • Inspect embedded raster content even when the container format is vector.

Graphics functions can belong to separate products. For example, basic plot, scatter, histogram, imagesc, surf, and tiledlayout are base MATLAB, while domain-specific statistical, mapping, image, signal, or medical visualizations can require named toolboxes.

Raw lines 33 to 50
51## Export with `exportgraphics`
53Prefer `exportgraphics` for current workflows:
55```matlab
56exportgraphics(fig, "overview.pdf", ContentType="vector");
57exportgraphics(ax1, "signal.png", Resolution=300);
58```
60R2026a-supported output includes:
62- raster: PNG, JPEG, TIFF, GIF;
63- vector-capable: PDF, SVG, EPS, and Windows-only EMF;
64- interactive HTML web canvas (new in R2026a).
66SVG support was added in R2025a. `Append=true` is supported for PDF and GIF,
67not every format. `ContentType` selects vector/image content for PDF, EPS,
68and EMF; choose SVG by its extension without relying on this option.
69Inspect export artifacts and any embedded images. `Resolution` has no effect
70on vector output or HTML. R2025a
71added dimensions/padding controls; verify exact option and unit support in the
72target release.
74Interactive HTML is active web content, not a static image. Review its
75embedded assets and distribution context; do not open an untrusted exported
76HTML file automatically.

Export with exportgraphics

Prefer exportgraphics for current workflows:

exportgraphics(fig, "overview.pdf", ContentType="vector");
exportgraphics(ax1, "signal.png", Resolution=300);

R2026a-supported output includes:

  • raster: PNG, JPEG, TIFF, GIF;
  • vector-capable: PDF, SVG, EPS, and Windows-only EMF;
  • interactive HTML web canvas (new in R2026a).

SVG support was added in R2025a. Append=true is supported for PDF and GIF, not every format. ContentType selects vector/image content for PDF, EPS, and EMF; choose SVG by its extension without relying on this option. Inspect export artifacts and any embedded images. Resolution has no effect on vector output or HTML. R2025a added dimensions/padding controls; verify exact option and unit support in the target release.

Interactive HTML is active web content, not a static image. Review its embedded assets and distribution context; do not open an untrusted exported HTML file automatically.

Raw lines 51 to 77
78### Which export API?
80| API | Prefer for | Notes |
81|---|---|---|
82| `exportgraphics` | axes, layouts, figures, publication files | current default; crop/padding, vector/raster, multipage PDF |
83| `copygraphics` | clipboard | interactive transfer; not reproducible file output |
84| `exportapp` | app/UI capture | UI-focused behavior |
85| `print` | legacy/device-specific workflows | behavior and UI support differ |
86| `savefig` | editable MATLAB figure | MATLAB object artifact, not archival interchange |
87| `saveas` | simple legacy save | less control than `exportgraphics` |
88| `imwrite` | image arrays/animated GIF construction | not a general figure renderer |
90Never treat `.fig` as passive. It stores MATLAB graphics objects and should be
91handled as an untrusted MATLAB object artifact unless its provenance is known.

Which export API?

APIPrefer forNotes
exportgraphicsaxes, layouts, figures, publication filescurrent default; crop/padding, vector/raster, multipage PDF
copygraphicsclipboardinteractive transfer; not reproducible file output
exportappapp/UI captureUI-focused behavior
printlegacy/device-specific workflowsbehavior and UI support differ
savefigeditable MATLAB figureMATLAB object artifact, not archival interchange
saveassimple legacy saveless control than exportgraphics
imwriteimage arrays/animated GIF constructionnot a general figure renderer

Never treat .fig as passive. It stores MATLAB graphics objects and should be handled as an untrusted MATLAB object artifact unless its provenance is known.

Raw lines 78 to 92
93## Headless and batch behavior
95`matlab -batch` starts without the desktop but can still display figure windows
96unless `-noFigureWindows` or `-nodisplay` is added. Rendering may depend on
97graphics hardware, fonts, installed system support, and platform. A planner
98should distinguish:
100- **compute-only**: no figures;
101- **off-screen export**: figures created but not shown;
102- **interactive graphics**: requires a display and user;
103- **web-canvas export**: generates active HTML.
105The bundled command planner only returns argv and never starts MATLAB.
106Review trusted code, fonts, output paths, overwrite policy, and license before
107an approved run.
109For deterministic export:
1111. create a new explicit figure;
1122. set size/units, axes limits, color limits, and fonts;
1133. avoid dependence on desktop defaults and current objects;
1144. set RNG before randomized jitter/layout;
1155. export to a new local path and refuse unintended overwrite;
1166. inventory output dimensions, file type, fonts, and embedded raster content;
1177. compare images with an appropriate visual tolerance, not byte equality.

Headless and batch behavior

matlab -batch starts without the desktop but can still display figure windows unless -noFigureWindows or -nodisplay is added. Rendering may depend on graphics hardware, fonts, installed system support, and platform. A planner should distinguish:

  • compute-only: no figures;
  • off-screen export: figures created but not shown;
  • interactive graphics: requires a display and user;
  • web-canvas export: generates active HTML.

The bundled command planner only returns argv and never starts MATLAB. Review trusted code, fonts, output paths, overwrite policy, and license before an approved run.

For deterministic export:

  1. create a new explicit figure;
  2. set size/units, axes limits, color limits, and fonts;
  3. avoid dependence on desktop defaults and current objects;
  4. set RNG before randomized jitter/layout;
  5. export to a new local path and refuse unintended overwrite;
  6. inventory output dimensions, file type, fonts, and embedded raster content;
  7. compare images with an appropriate visual tolerance, not byte equality.
Raw lines 93 to 118
119## Color and layout
121```matlab
122colororder(ax1, orderedColors);
123colormap(ax2, "parula");
124clim(ax2, [lowerLimit upperLimit]);
125axis(ax2, "tight");
126```
128Use a sequential map for ordered magnitude, a diverging map around a meaningful
129center, and distinct categorical colors for unordered groups. Avoid `jet` for
130quantitative interpretation. Keep a shared color scale when panels are meant
131to be compared.
133Use `tiledlayout`/`nexttile` rather than new `subplot` code. Legends and
134colorbars can belong to an axes or layout; make ownership explicit.

Color and layout

colororder(ax1, orderedColors);
colormap(ax2, "parula");
clim(ax2, [lowerLimit upperLimit]);
axis(ax2, "tight");

Use a sequential map for ordered magnitude, a diverging map around a meaningful center, and distinct categorical colors for unordered groups. Avoid jet for quantitative interpretation. Keep a shared color scale when panels are meant to be compared.

Use tiledlayout/nexttile rather than new subplot code. Legends and colorbars can belong to an axes or layout; make ownership explicit.

Raw lines 119 to 135
136## Time, table, and categorical plots
138Many plotting functions accept tables directly. This preserves variable-name
139selection but does not remove the need to validate types and missing data.
141```matlab
142plot(T, "Time", ["Observed" "Predicted"]);
143legend(["Observed" "Predicted"], Location="best");
144```
146Sort time values and define duplicate/missing handling before plotting.
147Categorical order controls axis/group order. Avoid silently dropping missing
148values without reporting the count.

Time, table, and categorical plots

Many plotting functions accept tables directly. This preserves variable-name selection but does not remove the need to validate types and missing data.

plot(T, "Time", ["Observed" "Predicted"]);
legend(["Observed" "Predicted"], Location="best");

Sort time values and define duplicate/missing handling before plotting. Categorical order controls axis/group order. Avoid silently dropping missing values without reporting the count.

Raw lines 136 to 149
150## 3-D, transparency, and large data
1523-D surfaces, transparency, lighting, and very dense primitives can force
153rasterization or produce platform-specific output. For large data:
155- decimate only with a documented visual/statistical rule;
156- preserve extremes and events;
157- distinguish display reduction from analysis data;
158- record the displayed sample count and aggregation;
159- test export memory and file size.

3-D, transparency, and large data

3-D surfaces, transparency, lighting, and very dense primitives can force rasterization or produce platform-specific output. For large data:

  • decimate only with a documented visual/statistical rule;
  • preserve extremes and events;
  • distinguish display reduction from analysis data;
  • record the displayed sample count and aggregation;
  • test export memory and file size.
Raw lines 150 to 160
161## Review checklist
163- [ ] Every object has an explicit parent handle.
164- [ ] Data transformations and missing-value counts are documented.
165- [ ] Axes, units, limits, and color scale are intentional.
166- [ ] Product/toolbox requirements are declared.
167- [ ] Output path is local, new, and reviewed.
168- [ ] Vector versus raster intent is explicit.
169- [ ] HTML and `.fig` outputs are treated as active/object artifacts.
170- [ ] Fonts and embedded raster content are inspected.
171- [ ] Batch mode and display requirements are compatible.
172- [ ] Accessibility and final-size readability were reviewed.

Review checklist

  • [ ] Every object has an explicit parent handle.
  • [ ] Data transformations and missing-value counts are documented.
  • [ ] Axes, units, limits, and color scale are intentional.
  • [ ] Product/toolbox requirements are declared.
  • [ ] Output path is local, new, and reviewed.
  • [ ] Vector versus raster intent is explicit.
  • [ ] HTML and .fig outputs are treated as active/object artifacts.
  • [ ] Fonts and embedded raster content are inspected.
  • [ ] Batch mode and display requirements are compatible.
  • [ ] Accessibility and final-size readability were reviewed.
Raw lines 161 to 173
174## Sources (reviewed 2026-10-01)
176- [`tiledlayout`](https://www.mathworks.com/help/matlab/ref/tiledlayout.html)
177- [`exportgraphics`](https://www.mathworks.com/help/matlab/ref/exportgraphics.html)
178- [Compare Ways to Export Graphics](https://www.mathworks.com/help/matlab/creating_plots/compare-ways-to-export-save-graphics-plots-from-figures.html)
179- [`copygraphics`](https://www.mathworks.com/help/matlab/ref/copygraphics.html)
180- [`exportapp`](https://www.mathworks.com/help/matlab/ref/exportapp.html)
181- [MATLAB Graphics](https://www.mathworks.com/help/matlab/graphics.html)
182- [MATLAB release notes](https://www.mathworks.com/help/matlab/release-notes.html)
183- [`matlab -batch` behavior on Linux](https://www.mathworks.com/help/matlab/ref/matlablinux.html)

Sources (reviewed 2026-10-01)

  • [tiledlayout](https://www.mathworks.com/help/matlab/ref/tiledlayout.html)
  • [exportgraphics](https://www.mathworks.com/help/matlab/ref/exportgraphics.html)
  • Compare Ways to Export Graphics
  • [copygraphics](https://www.mathworks.com/help/matlab/ref/copygraphics.html)
  • [exportapp](https://www.mathworks.com/help/matlab/ref/exportapp.html)
  • MATLAB Graphics
  • MATLAB release notes
  • [matlab -batch behavior on Linux](https://www.mathworks.com/help/matlab/ref/matlablinux.html)
Raw lines 174 to 183