Print figure or save to specific file format
print( specifies the printer. Specify the
printer as a character vector or string containing the printer name preceded by
-P, for example,
'-Pmy printer'. The
printer must be set up on your system.
the driver. Use this option if you want to ensure that the printed
output is either black and white or color.
print( maximizes the figure
size to fill the page. Specify
'-bestfit' to preserve the figure's aspect ratio or
'-fillpage' to ignore the aspect ratio. These options are
valid only when saving to a page format (PDF, and PS) or printing to a printer.
Use this option with any of the input arguments from the previous
print( uses the specified
resolution. Specify the resolution as a character vector or string containing an
integer value preceded by
-r, for example,
'-r200'. Use this option with any of the input arguments
from the previous syntaxes.
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 also 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')
Save a figure that fills the page using the
bar([1 10 7 8 2 2 9 3 6]) print('FillPageFigure','-dpdf','-fillpage')
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
Create a surface plot. Return the RGB image data for the
figure and specify the image resolution. Then, convert the image data to a movie
surf(peaks) cdata = print('-RGBImage','-r120'); F = im2frame(cdata);
filename— File name
File name, specified as a character vector or string containing the desired file name and path.
'My Saved Chart'
'Folder\My Saved Chart'
"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, the format, and your system resolution. Bitmap images are widely used by Web browsers and other applications that display graphics. However, they do not support transparency or 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. Also, 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, try to make all the necessary changes while your figure is still in MATLAB®.
If you set the
Renderer property for the figure, then
Renderer property for the figure to
'painters' or specify
'-painters' as an input argument to
If you want output that has transparency, then create a vector graphics file using a Metafile, PDF, or SVG format. If you use a PS or EPS format, then transparency is only supported for the figure and axes backgrounds. Bitmap images do not support transparency, but will closely match what is shown on screen to give the appearance of transparency.
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
for the figure or specify the
argument to 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|
You cannot save Simulink block diagrams in PostScript or EPS formats.
Only PDF and full-page PS formats use the first two elements of
PaperPosition property. Other formats ignore
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 name
Printer name, specified as a character vector or string containing
the printer name.
'-Pmy local printer'
"-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
'-dprnc'. 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||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)
'-dpdf' — PDF file (Windows and Mac OS)
resize— Option to expand figure to fill page
Option to expand figure to fill page, specified as one of these values:
'-fillpage' — Maximize the
size of the figure to fill the page. Leave a .25 inch margin on all
sides of the page. The tick marks, layout, and aspect ratio of the
figure might change.
'-bestfit' — Maximize the
size of the figure to fill the page, but preserve the aspect ratio
of the figure. The figure might not fill the entire page. This option
leaves a minimum page margin of .25 inches.
Both options are valid only when printing a figure to a printer or saving to a page format such as PDF and PS. They are not valid for Simulink block diagrams.
Resolution, specified as a character vector or a string containing
an integer value indicating the resolution in dots per inch. For example,
'-r300' sets the output resolution to 300 dots per
inch. To specify screen resolution, use
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.
Specifying the resolution is useful when creating a bitmap image or when using the OpenGL renderer with a vector graphics file format (since OpenGL produces a bitmap image even with vector formats). Specifying the resolution has no effect when using the Painters renderer with a vector graphics file format, since Painters produces a true vector graphics file that contains the commands that redraw the figure.
Simulink printing does not support the resolution option. For higher quality output of Simulink models, use a vector format such as SVG or PDF.
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
'-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
Sometimes, saving a file with the
can cause longer rendering times and, in rare cases, might not accurately
arrange graphics objects in 3-D views. Also, the Painters renderer
cannot print or save lines thinner than one pixel.
If you do not specify the renderer, then
Renderer property for the
fig— Figure, 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
You cannot save Simulink block diagrams in PostScript or EPS formats.
cdata— Image data
Image data, returned as an n-by-m-by-3 array. The size of the
image data array depends on the
of the figure and the output resolution.
Starting in R2015b, if you use
'-r0' option on a high-resolution system, then
the size of the
cdata output array is larger than
in previous releases or on other systems. Also, the number of elements
cdata might not match the size of the figure
in pixels based on the figure’s
and the root’s
For more information, see DPI-Aware Behavior in MATLAB.
Starting MATLAB in no display mode on Linux or
-noFigureWindows startup option on any
platform has these limitations for
Printing or saving figures with visible uicontrols
errors. To print or save the figure, hide the uicontrols by setting
Visible properties to
or use the
'-noui' option with the
Always uses the painters renderer, even if you specify
The current figure is typically the last figure that you create or click with the mouse. User interaction can change the current figure.
To print a specific figure, specify the figure as the first input
argument. If you do not specify a figure, then the
returns empty, then
Starting in R2016a, printed and saved figures match the size of the figure on the screen by default. Previously, printed and saved figures were 8-by-6 inches by default.
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 |
If you are using a Linux or Mac system and get an error about an invalid or unrecognized printer,
then try specifying a PostScript driver for the
driver option. If the printer
supports PostScript level 3, try
'-dps' for black and white or
'-dpsc' for color. If the printer supports PostScript level 2, then try
'-dps2' for black and white
'-dps2c' for color. For
printoptfile. Alternatively, print the figure to a PDF file. Then, print the PDF from an external PDF viewer.
If you print a figure that has a callback defined
SizeChangedFcn property and if the output
size differs from the size of the figure on the screen, then the
for the figure to