Save Plot as Image or Vector Graphics File
You can save plots as images or as vector graphics files. When deciding between the two types of content, consider the quality, file size, and formatting requirements for your situation. Regardless of the file format you choose, you can get the best results by finalizing your content in the MATLAB® figure before saving your file.
Image file formats include JPEG, PNG, GIF, and TIFF. These files contain pixels, which are ideal for representing pictorial images and complex surfaces. In some cases, you might need to save an image at a higher resolution to satisfy certain quality requirements. Higher resolution files tend to be larger, which can make them difficult to use in bandwidth-constrained situations. Also, it can be difficult to edit lines and text in an image without introducing artifacts. Most applications support image files.
Vector graphics file formats include SVG, PDF, EPS, and EMF. These files contain instructions for drawing lines, curves, and polygons. Some vector graphics files also include image content. These file formats are ideal for representing simple graphics, but certain surfaces and mesh plots are too complex to be represented using vector content. Some applications offer extensive editing capabilities for vector graphics files, while others only support scaling.
This table shows some examples and features of images and vector graphics. While the
examples use the exportgraphics function, you can also use the uiexportdlg function or choose options on the figure toolstrip or axes
toolbar to save a plot to a file.
| Images | Vector Graphics | |
|---|---|---|
Example | Create a pie chart and export it as a PNG file. To create
an image that is about the same size as the MATLAB figure, get the graphics root
piechart([10 25 30 5]) sppi = get(groot,"ScreenPixelsPerInch"); exportgraphics(gcf,"PieChart.png",Resolution=sppi) | Create a pie chart and export it as a PDF file. By default,
piechart([10 25 30 5]) exportgraphics(gcf,"PieChart.pdf",ContentType="vector") |
Scaling | Images can look blurry or display artifacts if you scale
them. For best results, set the
| You can scale vector graphics without losing sharpness. However, the content scales together, including fonts, markers, and patch edges. If you make a large scaling adjustment, the scaled graphic might not look the way you expected. For best results, set the size of the figure to approximately the same size as the vector graphic you want to save. |
Complicated Graphics | Images can contain complicated graphics if you export them using a sufficient resolution. | Complicated graphics, such as surfaces with large numbers of grid points and transparency effects, take a long time to display. In addition, the exported graphic might not display certain aspects of 3-D scenes accurately. In these cases, consider exporting the figure as an image. |
Embedded Fonts |
|
|
| Transparent Backgrounds |
|
piechart([10 25 30 5]) exportgraphics(gcf,"PieChartBg.pdf",ContentType="vector", ... BackgroundColor="none") |
See Also
exportgraphics | copygraphics | uiexportdlg