print — Export a figure to a PNG file.
print writes the active or selected figure as a PNG through the current filesystem provider. It supports MATLAB-style filename, -dpng, and resolution options. Other printer and vector-image devices are not available in this exporter.
Syntax
print(filename)
print(filename, '-dpng', '-rN')
print(fig, filename, ___)
ok = print(filename, ___)Inputs
filename- Type
StringScalar- Required
- Yes
- Description
- PNG destination; .png is appended when absent.
options- Type
Any- Required
- Variadic
- Description
- Optional -dpng and -rN tokens in either order with the filename.
fig- Type
Any- Required
- Yes
- Description
- Figure handle or RunMat-only typed-integer handle alias.
options- Type
Any- Required
- Variadic
- Description
- Optional -dpng and -rN tokens.
Returns
ok- Type
LogicalArray- Description
- RunMat-only logical completion status.
Errors
RunMat:print:InvalidInput- When
- The filename, figure handle, or argument ordering is invalid.
- Message
print: invalid input arguments
RunMat:print:UnsupportedDevice- When
- The requested device is not supplied by the active exporter.
- Message
print: unsupported output device
RunMat:print:InvalidOption- When
- An option token or resolution is invalid, a device is duplicated, or PNG dimensions exceed supported limits. Repeated resolution tokens use the last value.
- Message
print: invalid option
Forms and options
print(filename) and print(filename,'-dpng') export the current figure. print(fig,filename,'-dpng') chooses a figure explicitly. Device and filename text can occur in command-style order, including print -dpng command_style_plot.png.
-rN changes the output dimensions relative to the default 800-by-600 canvas at 150 DPI; -r0 selects that default. If repeated, the last resolution token wins. PNG is the only available device. Recognized PDF, EPS, and SVG requests fail with an unsupported-device error rather than producing PNG under another extension.
A filename without .png receives that extension. A requested logical success output is a RunMat extension; MATLAB-compatible file-export forms are statement calls. Typed-integer figure aliases are also RunMat-only and must exactly identify a graphics handle.
Storage and execution
The output is written through the selected filesystem authority. Native hosts can export to ordinary paths; browser hosts write to their installed virtual filesystem, from which the host can expose a download artifact. Export does not change figure data or the current directory.
Filename and option operands can materialize on the host. Plot data retained by the scene may be rendered through the shared WGPU path and fall back to CPU rasterization when headless GPU initialization is unavailable. print itself is an I/O and fusion boundary, not a numeric GPU kernel; it does not change plot-data residency.
A host-known figure is copied before operand materialization. A resident numeric figure handle is selected after its value materializes; that selected scene is then copied before rendering. Figure changes before resident-handle selection may appear in the export, while later changes do not alter the copied scene.
The file-export call can suspend during rendering or publication. Failures retain the rendering or filesystem cause; a rejected device or malformed host option has no file effect.
Examples
Export the active figure to PNG
x = 0:0.1:2*pi;
plot(x,sin(x));
print('sine_plot','-dpng');
info = imfinfo('sine_plot.png');Export at a higher resolution
x = 0:0.1:1;
plot(x,x.^2,'LineWidth',2);
print('quadratic_plot','-dpng','-r300');
info = imfinfo('quadratic_plot.png');Export a selected figure
fig = figure();
plot(1:5,[1 4 2 5 3]);
print(fig,'explicit_handle_plot.png','-dpng');
info = imfinfo('explicit_handle_plot.png');Put the device option before the filename
plot(1:4,[1 3 2 4]);
print -dpng command_style_plot.png
info = imfinfo('command_style_plot.png');Request the RunMat export status
plot(1:3,[2 1 3]);
ok = print('status_plot','-dpng');
info = imfinfo('status_plot.png');Using print with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how print changes the result.
Run a small print example, explain the result, then change one input and compare the output.
FAQ
Which formats does print support?⌄
PNG is available via -dpng or a .png filename. PDF, EPS, and SVG device tokens are recognized but unavailable in the current exporter.
Where is a browser export written?⌄
To the selected virtual filesystem. The browser host may expose that file as a downloadable artifact.
Does -r300 change plot data?⌄
No. It changes the exported pixel dimensions only.
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 · 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
Source you can read
Every RunMat function's source is public. Read exactly how print is executed, line by line, in Rust.
- View the source for print in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
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.