Print figure or save to specific file format
cdata = print('-RGBImage');example
the printer. Specify the printer as a string containing the printer
name preceded by
-P, for example,
printer'. The printer must be setup on your system.
the driver for the temporary file that
the specified resolution. Specify the resolution as a string containing
an integer value preceded by
-r, for example,
Use this option with any of the input arguments from the previous
the specified renderer. Specify the renderer as either
user interface controls, such as push buttons and sliders, from the
saved or printed output. It does not exclude user interface objects
that can contain an axes, such as a uitab or uipanel.
the RGB image data for the current figure. This option differs from
screen captures in that all printing features apply to the output.
You can additionally specify the
cdata = print('-RGBImage');
fig options with this syntax. However, you
cannot specify a Simulink block diagram.
Create a bar chart and print it to your system
default printer. If you do not specify the figure to print, then
Create a plot and copy it to the system clipboard.
You can paste the copied plot into other applications.
Create a plot and save it as a PNG image file.
Create a plot and save it as an Encapsulated PostScript® file.
Save the current figure as an Encapsulated PostScript File and add a TIFF preview.
Save a specific figure by passing its object
fig = figure; plot(1:10) print(fig,'MySavedPlot','-dpng')
Alternatively, refer to a figure using the value of its
which is the integer value that displays in the figure window title
bar. For example, save the figure with
Figure 2 displayed
in the title bar. Precede the integer value by
figure(2); plot(1:10) print('-f2','MySavedPlot','-dpng')
Save a surface plot to a PNG file. Set the
for the figure to
'auto' so that it saves at the
size displayed on the screen. Use
'-r0' to save
it with screen resolution.
surf(peaks) set(gcf,'PaperPositionMode','auto') print('PeaksSurface','-dpng','-r0')
Create a figure with a push button that clears the axes. Save the figure to a JPEG file without saving the push button.
surf(peaks) uicontrol('Style','pushbutton','String','Clear',... 'Position',[20 20 50 20],'Callback','cla'); print('SurfacePlot','-djpeg','-noui')
Return the RGB image data for a figure.
surf(peaks) cdata = print('-RGBImage');
Display the image data at full resolution using
filename— File namestring
File name, specified as a string containing the desired file name and path.
'My Saved Chart'
'Folder\My Saved Chart'
The maximum file name length, including the path, is operating system and file format specific. Typically, the file name should be no more than 126 characters, or if you include the path, then no more than 128 characters.
formattype— File format
File format, specified as one of the options in these tables.
Bitmap images contain a pixel-based representation of the figure. The size of the generated file depends on the figure and the format used. Bitmap images are widely used by Web browsers and other applications that display graphics. However, they do not scale well and you cannot modify individual graphics objects, such as lines and text, in other graphics applications.
This table lists the supported bitmap image formats.
|Option||Bitmap Image Format||Corresponding File Extension|
|TIFF 24-bit (compressed)|
|TIFF 24-bit (not compressed)|
|Enhanced metafile (Windows only)|
|BMP 8-bit (256 color, uses a fixed colormap)|
|PBM (plain format) 1-bit|
|PBM (raw format) 1-bit|
|PCX 24-bit color (three 8-bit planes)|
|PCX 8-bit newer color (256 color)|
|PCX older color (EGA/VGA 16-color)|
|PGM (plain format)|
|PGM (raw format)|
|PPM (plain format)|
|PPM (raw format)|
Vector graphics files store commands that redraw the figure. This type of format scales well, but can result in a large file. Additionally, it might not produce the correct 3-D arrangement of objects in certain cases. Some applications support extensive editing of vector graphics formats. However, some applications do not support editing beyond resizing the graphic. In general, you should try to make all the necessary changes while your figure is still in MATLAB®.
If you set the
Renderer property for the
Renderer property for the figure to
'-painters' as an input argument to
The default figure renderer is OpenGL. If the figure renderer
differs from the renderer used when generating output, some details
of the saved figure can differ from the figure on the display. If
necessary, you can make the displayed figure and the saved figure
use the same renderer. Set the
This table lists the supported vector graphics formats.
|Option||Vector Graphics Format||Corresponding File Extension|
|Full page Portable Document Format (PDF) color|
|Encapsulated PostScript (EPS) Level 3 black and white|
|Encapsulated PostScript (EPS) Level 3 color|
|Encapsulated PostScript (EPS) Level 2 black and white|
|Encapsulated PostScript (EPS) Level 2 color|
|Enhanced Metafile (Windows® only)|
|SVG (scalable vector graphics)|
|Full-page PostScript (PS) Level 3 black and white|
|Full-page PostScript (PS) Level 3 color|
|Full-page PostScript (PS) Level 2 black and white|
|Full-page PostScript (PS) Level 2 color|
Only PDF and PS formats use the
formatoptions— Additional formatting options
Additional formatting options supported by some file formats, specified as one or more of these values:
'-tiff' — Include a TIFF
preview. EPS files only.
'-loose' — Use a loose bounding
box. EPS and PS files only.
'-cmyk' — Use CMYK colors
instead of RGB colors. EPS and PS files only.
'-append' — Append the figure
to an existing PS file. PS files only.
print('my file','-deps','-tiff','loose') saves
the current figure to the file
my file.eps using
a loose bounding box and includes a TIFF preview.
printer— Printer namestring containing
-Pand printer name
Printer name, specified as a string containing
'-Pmy local printer'
To view a list of available printers, use this command:
[~,printers] = findprinters
If you do not specify a printer, then
driver— Printer driver
Printer driver, specified as
'-dpsc2'. If you do not specify a driver, then
The option you use depends on your system, for example:
|Windows||Black and white|
|Linux® or Mac OS X||Black and white|
clipboardformat— Format copied to clipboard
Format copied to clipboard, specified as one of these options:
'-dmeta' — Enhanced metafile
'-dbitmap' — Bitmap image
(Windows and Mac OS X)
'-dpdf' — PDF file (Windows and Mac OS X)
resolution— Resolutionstring containing
Resolution, specified as a string containing
an integer value indicating the resolution in dots per inch. For example,
the output resolution to 300 dots per inch. To specify screen resolution,
In general, using a higher resolution value yields higher quality output, but at the cost of higher memory use and larger output files. The higher the resolution setting, the longer it takes to render your figure. By default, the resolution is 90 dpi for Simulink models and 150 dpi for figures. For typical laser-printer output, the default resolution of 150 dpi for figures is normally adequate. However, if you are preparing figures for high-quality printing, such as a textbook or color brochures, you might want to use 200 or 300 dpi. The resolution can be limited by the printer's capabilities.
Specifying the resolution is useful if you want to scale a bitmap image or a vector graphics file that contains an embedded image. At ordinary magnification, the effect is subtle. The effect is most apparent when viewing the output at a higher magnification or when printed.
renderer— Graphics renderer
Graphics renderer, specified as
'-opengl' — OpenGL renderer.
Use this renderer when saving bitmap images. OpenGL produces
a bitmap image even with vector formats, which might limit the extent
to which you can edit the image in other applications.
'-painters' — Painters renderer.
Use this renderer when saving vector graphics files. If you save to
a vector graphics file and if the figure
is set to
In some cases, saving a file with the
If you do not specify the renderer, then
for the figure, then
fig— Figure or Simulink block diagramfigure object | Simulink block diagram
Figure object or Simulink block diagram. You can refer
to a figure using either its object variable name or using the figure
number preceded by
-f. For example,
to the figure with a
Number property value of
When specifying a Simulink block diagram, precede the model name
-s. Specify the current model using
Starting MATLAB in no display mode on Linux or
-noFigureWindows startup option on any
platform has these limitations for
Does not print or save uicontrols.
Always uses the painters renderer, even if you specify
You can set properties of the figure to control some printing and saving parameters. This table lists properties of the figure related to printing and saving.
|Size of the printed or saved figure. If printing to a printer or a full-page output format, then this property also determines the figure location on the page.|
|Specifies whether to use the |
|Specifies whether to use the current background color of the figure or to change the background color to white when printing or saving the figure.|
|Figure orientation on printed page.|
|Standard printer paper size.|
|Custom width and height of printer paper.|
|Units for the |
To avoid the warning, set the
for the figure to