print
Export a figure to an image or document file.
📝Syntax
print(filename)
print(filename, formatoption)
print(fig, filename)
print(fig, filename, formatoption)
print(fig, filename, formatoption, resolution)
📥Input Arguments
Parameter Description
fig Figure graphics object. When omitted, the current figure returned by gcf() is used.
filename Character vector or string scalar: destination filename.
formatoption Character vector or string scalar: a -d device option (for example '-dpng', '-dpdf', '-dsvg'). When omitted, the format is inferred from the filename extension.
resolution Character vector or string scalar: a -r resolution option (for example '-r150'). Accepted for compatibility; the export follows the figure size.
📄Description

print exports a figure to an image or document file. It is a thin wrapper over saveas: the -d device option selects the output format and the figure is exported through the shared desktop, web and headless renderer.

When no -d device is given, the format is inferred from the filename extension, and PNG is used when the filename has no extension. A -r resolution option is accepted for compatibility but does not resample the output.

The device option maps to the same format registry as saveas:

Device option Format Extension
-dpng Portable Network Graphics .png
-djpeg, -djpg JPEG .jpg
-dtiff, -dtiffn, -dtif TIFF .tif
-dbmp Bitmap .bmp
-dgif Graphics Interchange Format .gif
-dwebp WebP .webp
-dsvg Scalable Vector Graphics .svg
-dpdf Portable Document Format .pdf

Background: as with saveas, while the figure InvertHardcopy property is 'on' (the default), the exported background is white whatever the on-screen figure Color.

💡Examples
Export the current figure to PNG, PDF and SVG.
f = figure('Visible', 'off');
plot(1:10, (1:10) .^ 2);
title('Quadratic data');
print(f, [tempname(), '.png'], '-dpng');
print(f, [tempname(), '.pdf'], '-dpdf');
print(f, [tempname(), '.svg'], '-dsvg', '-r150');
close(f);
Infer the format from the filename extension.
f = figure('Visible', 'off');
plot(1:5);
pngfile = [tempname(), '.png'];
print(pngfile);
assert(isfile(pngfile));
close(f);
🔗See Also
saveassavefiggcf
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub