Print figure or save to specific file format


  • print(filename,formattype) example
  • print(filename,formattype,formatoptions)
  • print example
  • print(printer)
  • print(driver)
  • print(printer,driver)
  • print('-clipboard',clipboardformat) example
  • cdata = print('-RGBImage'); example



print(filename,formattype) saves the current figure to a file using the specified file format. If the file name does not include an extension, then print appends the appropriate one.

print(filename,formattype,formatoptions) specifies additional options that are available for some formats.


print prints the current figure to the default printer.

print(printer) specifies the printer. Specify the printer as a string containing the printer name preceded by -P, for example, '-Pmy printer'. The printer must be setup on your system.

print(driver) specifies the driver for the temporary file that print generates and sends to the printer. Specify a driver if you want to ensure that the printed output is either black and white or color.

print(printer,driver) specifies the printer and the driver.


print('-clipboard',clipboardformat) copies the current figure to the clipboard using the specified format. You can paste the copied figure into other applications.


print(resolution,___) uses the specified resolution. Specify the resolution as a string containing an integer value preceded by -r, for example, '-r200'. Use this option with any of the input arguments from the previous syntaxes.


print(renderer,___) uses the specified renderer. Specify the renderer as either '-painters' or '-opengl'.


print('-noui',___) excludes 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.


print(fig,___) saves or prints the figure or Simulink® block diagram specified by fig instead of the current figure.


cdata = print('-RGBImage'); returns 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 resolution, renderer, '-noui', and fig options with this syntax. However, you cannot specify a Simulink block diagram.


collapse all

Print Paper Copy of Figure

Create a bar chart and print it to your system default printer. If you do not specify the figure to print, then print uses the current figure.


Copy Figure to Clipboard

Create a plot and copy it to the system clipboard.


You can paste the copied plot into other applications.

Save Figure as Image File

Create a plot and save it as a PNG image file.


print saves the plot as BarPlot.png.

Save Figure as Vector Graphics File

Create a plot and save it as an Encapsulated PostScript® file.


print saves the plot as BarPlot.eps.

Add TIFF Preview to EPS File

Save the current figure as an Encapsulated PostScript File and add a TIFF preview.


Specify Figure to Save

Save a specific figure by passing its object variable to print.

fig = figure;

Alternatively, refer to a figure using the value of its Number property, 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 -f.


Save Figure at Screen Size and Resolution

Save a surface plot to a PNG file. Set the PaperPositionMode property for the figure to 'auto' so that it saves at the size displayed on the screen. Use '-r0' to save it with screen resolution.


Save Figure Without Saving UIControls

Create a figure with a push button that clears the axes. Save the figure to a JPEG file without saving the push button.

    'Position',[20 20 50 20],'Callback','cla');

Return RGB Image Data for Figure

Return the RGB image data for a figure.

cdata = print('-RGBImage');

Display the image data at full resolution using imshow.


Input Arguments

collapse all

filename — File namestring

File name, specified as a string containing the desired file name and path.

Example: 'My Saved Chart'

Example: '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'-djpeg' | '-dpng' | '-dtiff' | '-dpdf' | '-deps' | ...

File format, specified as one of the options in these tables.

Bitmap Image File

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.

OptionBitmap Image FormatCorresponding File Extension
'jpeg'JPEG 24-bit.jpg
'png'PNG 24-bit.png
'tiff'TIFF 24-bit (compressed).tif
'tiffn'TIFF 24-bit (not compressed).tif
'meta'Enhanced metafile (Windows only).emf
'bmpmono'BMP Monochrome .bmp
'bmp'BMP 24-bit .bmp
'bmp16m'BMP 24-bit .bmp
'bmp256'BMP 8-bit (256 color, uses a fixed colormap) .bmp
'hdf'HDF 24-bit.hdf
'pbm'PBM (plain format) 1-bit.pbm
'pbmraw'PBM (raw format) 1-bit.pbm
'pcxmono'PCX 1-bit.pcx
'pcx24b'PCX 24-bit color (three 8-bit planes).pcx
'pcx256'PCX 8-bit newer color (256 color).pcx
'pcx16'PCX older color (EGA/VGA 16-color).pcx
'pgm'PGM (plain format).pgm
'pgmraw'PGM (raw format).pgm
'ppm'PPM (plain format).ppm
'ppmraw'PPM (raw format).ppm

Vector Graphics File

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 figure, then print uses that renderer when generating output. Otherwise, print chooses the appropriate renderer. Typically, print uses the Painters renderer when generating vector graphics files. For some complex figures, print uses the OpenGL® renderer instead. If it uses the OpenGL renderer, then the vector graphics file contains an embedded image, which might limit the extent to which you can edit the image in other applications. To ensure that print uses the Painters renderer, set the Renderer property for the figure to 'painters' or specify '-painters' as an input argument to print.

    Note:   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 Renderer property for the figure or specify the renderer input argument to the print function.

This table lists the supported vector graphics formats.

OptionVector Graphics FormatCorresponding File Extension
'pdf'Full page Portable Document Format (PDF) color.pdf
'eps'Encapsulated PostScript (EPS) Level 3 black and white.eps
'epsc'Encapsulated PostScript (EPS) Level 3 color.eps
'eps2'Encapsulated PostScript (EPS) Level 2 black and white.eps
'epsc2'Encapsulated PostScript (EPS) Level 2 color.eps
'meta'Enhanced Metafile (Windows® only).emf
'svg'SVG (scalable vector graphics).svg
'ps'Full-page PostScript (PS) Level 3 black and
'psc'Full-page PostScript (PS) Level 3
'ps2'Full-page PostScript (PS) Level 2 black and
'psc2'Full-page PostScript (PS) Level 2

    Note:   Only PDF and PS formats use the PaperOrientation property of the figure and the left and bottom elements of the PaperPosition property. Other formats ignore these values.

formatoptions — Additional formatting options'-tiff' | '-loose' | '-cmyk' | '-append'

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.

Example: 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 -P and printer name

Printer name, specified as a string containing -P and printer name.

Example: '-Pmy local printer'

To view a list of available printers, use this command:

[~,printers] = findprinters

If you do not specify a printer, then print uses the system default printer. If you want to set up a new printer or select a different default printer, use the operating system printer management utilities. Restart MATLAB if you do not see a printer that is already setup.

driver — Printer driver'-dwin' | '-dwinc' | '-dps' | '-dpsc' | '-dps2' | '-dpsc2'

Printer driver, specified as '-dwin', '-dwinc', '-dps', '-dpsc', '-dps2', or '-dpsc2'. If you do not specify a driver, then print relies on your operating system to choose the driver.

The option you use depends on your system, for example:

Windows'-dwin'Black and white
Linux® or Mac OS X'-dps' or '-dps2'Black and white
'-dpsc' or '-dpsc2'Color

clipboardformat — Format copied to clipboard-dmeta | -dbitmap | -dpdf

Format copied to clipboard, specified as one of these options:

  • '-dmeta' — Enhanced metafile (Windows only)

  • '-dbitmap' — Bitmap image (Windows and Mac OS X)

  • '-dpdf' — PDF file (Windows and Mac OS X)

resolution — Resolutionstring containing -r and integer

Resolution, specified as a string containing -r and 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 '-r0'.

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'-opengl' | '-painters'

Graphics renderer, specified as '-opengl' or '-painters'.

  • '-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 RendererMode property is set to 'auto', then print automatically attempts to use the Painters renderer. If you want to ensure that your output format is a true vector graphics file, then specify the Painters renderer. For example:


    Note:   In some cases, saving a file with the '-painters' option can cause longer rendering times and, in rare cases, might not accurately arrange graphics objects in 3-D views. Additionally, the Painters renderer cannot print or save lines thinner than 1 pixel.

If you do not specify the renderer, then print automatically uses the appropriate renderer to produce the output format that you request. However, if you set the Renderer property for the figure, then print uses that renderer when generating output.

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, -f2 refers to the figure with a Number property value of 2. When specifying a Simulink block diagram, precede the model name with -s. Specify the current model using '-s'.

Output Arguments

collapse all

cdata — Image datan-by-m-by-3 array

Image data, returned as an n-by-m-by-3 array.


  • print does not support capturing ActiveX® controls.

  • Starting MATLAB in no display mode on Linux or using the -noFigureWindows startup option on any platform has these limitations for print:

    • Does not print or save uicontrols.

    • Always uses the painters renderer, even if you specify the '-opengl' option.

More About

collapse all


  • 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.

    Figure PropertyDescription
    PaperPositionSize 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.
    PaperPositionModeSpecifies whether to use the PaperPosition property or the size of the figure on the screen to set the size of the printed or saved figure.
    InvertHardcopySpecifies whether to use the current background color of the figure or to change the background color to white when printing or saving the figure.
    PaperOrientationFigure orientation on printed page.
    PaperTypeStandard printer paper size.
    PaperSizeCustom width and height of printer paper.
    PaperUnitsUnits for the PaperSize and PaperPosition properties.

  • The print function returns a warning message when you print a figure that has a callback defined for the SizeChangedFcn property. To avoid the warning, set the PaperPositionMode property for the figure to 'auto'.

See Also

| |

Introduced before R2006a

Was this topic helpful?