Main Content

Compare Ways to Export Graphics from Figures

MATLAB® provides several functions for saving the contents of a figure or an app. Each function offers a different set of capabilities. This table provides a description of each function and some commonly used options. Use this table to decide which export function is appropriate for your workflow.

 exportgraphicsprintgetframe with imwriteexportapp

Description

Use exportgraphics when you want to save a plot and include it in documents, emails, or presentations.

Use print when you want to save a plot within a full-sized page.

Use getframe with imwrite when you have requirements that the other exporting functions cannot accommodate, such as exporting to a BMP file.

Use exportapp when you want to save a user interface (UI) you created in MATLAB and include it in documents, emails, or presentations.

Example

Export a plot in the current figure to a PNG file.

plot(1:10)
exportgraphics(gcf,"myplot.png")

Export a plot in the current figure as a full-page PDF file.

plot(1:10)
print(gcf,"myplot.pdf","-dpdf")

Capture a plot with getframe and save it as a BMP file.

plot(1:10)
F = getframe(gcf);
imwrite(F.cdata,"myplot.bmp")

Export an app window containing a button as a PNG file.

uif = uifigure;
uibutton(uif);
exportapp(uif,"myapp.png")

Type of Content Captured

  • Plots and charts in any type of figure, including figures created with the uifigure function (since R2025a)

  • Any type of axes

  • Legends, colorbars, annotations

  • Panels, tabs, tiled chart layouts

  • Plots and charts in any type of figure, including figures created with the uifigure function (since R2025a)

  • Any type of axes

  • Legends, colorbars, annotations

  • Panels, tabs, tiled chart layouts

  • Any type of figure, including figures created with the uifigure function

  • Any content within the figure, including UI components

  • Content in any type of figure, including figures created with the figure function (since R2025a)

  • All content in the app window, including plots and UI components

UI Component Support

No

exportgraphics does not capture most UI components, such as buttons or sliders. However, if you pass a UI container (such as a panel or tab) to exportgraphics, the function captures the plots in that container.

No (since R2025a)

Before R2025a: print captured UI components in figures created with the figure function only.

Yes

Yes

File Formats Supported

exportgraphics supports these formats:

  • Images: PNG, JPG, TIFF, and GIF

  • Vector graphics: SVG, EPS, EMF, and PDF

  • Animated images: GIF

print supports these formats:

  • Images: PNG, JPG, and TIFF

  • Vector graphics: SVG, EPS, EMF, and PDF

imwrite supports these formats:

  • Images: HDF4, PNG, JPG, TIFF, BMP, PBM, PGM, PPM, PCX, RAS, and GIF

  • Animated images: GIF

exportapp supports these formats:

  • Images: PNG, JPG, and TIFF

  • Vector graphics: PDF (Only UI components are stored as vector graphics; all other content, such as plots, are stored as images within the PDF.)

Multipage PDF Support

Yes

No

No

No

Cropping Control

Yes

The Padding name-value argument of the exportgraphics function enables you to specify a margin of padding around the axes. (since R2025a)

Before R2025a: exportgraphics cropped the output tightly around the axes and any associated titles, labels, colorbars, and legends.

No

print captures all the contents of the figure, including the white space that surrounds plots and other items in the figure.

The rect input argument of the getframe function enables you to select a section of the figure to capture.

No

exportapp captures all the contents of the app window, including the white space that surrounds UI components and plots.

Full-Page Format Support

No

Full-page controls are available for PDF or hard copy output by setting certain properties of the figure. See the Tips section of the print page for more information.

No

No

Embedded Font Support

exportgraphics automatically embeds fonts in PDFs when the fonts are embeddable.

No

No

exportapp automatically embeds fonts in PDFs when the fonts are embeddable.

Width and Height Control

Yes

The Width and Height name-value arguments of the exportgraphics function enable you to specify the size of the output. (since R2025a)

Before R2025a: Control the dimensions of the output by plotting into a tiled chart layout.

  • Page formats (PDF) — The PaperSize property of the figure controls the page size. The PaperPosition property of the figure controls the placement on the page.

  • Non-page formats (Images, EPS, EMF, SVG) — The PaperPosition property of the figure controls the dimensions of the image. The resolution input argument of the print function controls the number of pixels within those dimensions.

No

getframe captures the content to match the size on your display. However, imwrite has options for controlling how other applications display the pixels in TIFF and PNG files. Setting these options can affect the size of an image when it is rendered in another application.

No

Resolution Control

Yes

exportgraphics has a Resolution name-value argument for controlling the resolution of image files.

Yes

print has a resolution input argument for controlling the resolution of image files.

No

No

exportapp captures content at screen resolution.

Background Color and Transparency Control

Yes

exportgraphics has a BackgroundColor name-value argument for controlling the background color and transparency:

  • Colored background — Set BackgroundColor to a color value.

  • Transparent background (vector graphics file formats only) — Set BackgroundColor to "none".

No

However, before using print, you can set the background color and transparency by setting figure and axes properties:

  • Colored background — Set the Color property of the figure and the Color property of the axes to the intended color values.

  • Transparent background (vector graphics file formats only) — Set the Color properties of the figure and axes to "none".

  • The InvertHardcopy property of a figure has no effect, but you can still set the Color properties of the figure and axes to control the background color of the output. (since R2025a)

getframe captures the background color of the figure and axes as they appear on screen.

For PNG output, imwrite has an Alpha name-value argument for controlling the transparency of pixels by location and a Transparency name-value argument for controlling the transparency by pixel values.

No

exportapp captures the background color as it appears in the app window.

Preserved Axes Limits and Ticks Values

Yes

No

To ensure that the axes limits and tick values match your display, set all of these axes properties to "manual" after plotting.

  • XTickMode, YTickMode, and ZTickMode (for 3-D)

  • XTickLabelMode, YTickLabelMode, and ZTickLabelMode (for 3-D)

  • XLimMode, YLimMode, and ZLimMode (for 3-D)

For more information, see Axes Properties.

Yes

Yes

Related Functionality

  • In the figure toolstrip, in the Figure tab, click the Save As button.

  • Axes toolbar — Export button

  • copygraphics

  • In the figure toolstrip, in the Figure tab, click the Save As button.

  • saveas

See Also

Topics