|On this page…|
A graphics file format is a specification for storing and organizing data in a file. MATLAB® support exists for many different graphics file formats. Some are built-in and others are Ghostscript formats. File formats also differ in color support, graphics style (bitmap or vector), and bit depth.
This section provides information to help you decide which graphics format to use when exporting your figure to a file or to the Windows® clipboard. It covers
Before deciding on a graphics format, check what formats are supported by your target application and platform. See the print reference page for a complete list of supported MATLAB graphics formats. Once you decide on which format to use in exporting your figure, follow the instructions in Exporting to a File or Exporting to the Windows or Macintosh Clipboard.
Here are some of the more frequently used graphics formats. For a complete list, see the Graphics Format table on the print reference page. For a more complete description of these formats, see Description of Selected Graphics Formats.
Command Line -device Parameter
EPS color, and black and white
Export line plots or simple graphs to a file.
-deps (black and white)
-depsc -tiff (TIFF preview)
Export plots with surface lighting or transparency to a file. This format can be displayed by most Web browsers.
TIFF 24-bit bitmap color
Export plots with surface lighting or transparency to a file. Widely available. A good format to choose if you are not sure what formats your application supports.
BMP 8-bit color bitmap
Export a figure to the clipboard (Windows only).
EMF color vector format
Export a figure to the clipboard (Windows only).
There are at least five main factors to consider when choosing a graphics format to use in exporting a figure:
Implementation — Is it a built-in MATLAB or Ghostscript format?
Graphics Format — Is it bitmap or vector graphics format?
Bit Depth — What bit depth does the format offer?
Color Support — What color support does it have?
Model/Publication — Is it a Simulink® model or specific publication type?
Some graphics formats are built-in MATLAB formats and others are provided by Ghostscript. In some cases (such as the Windows Bitmap format), the format is available both as a built-in format and a Ghostscript format. In general, when this is the case, we recommend that you choose the MATLAB format, especially if you plan to read the image back into Windows later.
The choice of MATLAB versus Ghostscript formats is important when any of these properties affects your output:
Windows file formats are created using either bitmap or vector graphics. Bitmap formats store graphics as 2-D arrays of pixels. Vector formats use drawing commands to store graphics as geometric objects. Whether to use a bitmap or vector format depends mostly on the type of objects in your figure.
The choice of bitmap versus vector graphics is important when any of these properties or capabilities affects your output:
To create vector output, the Painters renderer is required. Under some circumstances you might need to manually select it in the Print Preview or Export Setup GUI. The painters renderer does not support lighting or transparency.
To create bitmap output, either the OpenGL® or the Z-buffer renderer is required. Under some circumstances you might need to manually select one of these in the Print Preview or Export Setup GUI. These renderers both support lighting, but only OpenGL supports transparency.
See Impact of Rendering Method on the Output for more information.
Bit depth is the number of bits a format uses to store each pixel. This determines the number of colors the exported figure can contain.
Bit depth applies mostly to bitmap graphics. An 8-bit image uses 8 bits per pixel (bpp), enabling it to define 28, or 256, unique colors. The other supported bit depths are 1-bit (2 colors), 4-bit (16 colors), and 24-bit (16 million colors).
In vector files that don't normally have a bit depth, the color of objects is specified by drawing commands stored in the file. However, vector files can contain bitmaps under the following conditions:
Image objects saved in vector formats are always saved as bitmaps, regardless of the rendering method used.
The Graphics Format table on the print reference page indicates the bit depth of each format. If file size is not critical, make sure you choose a format with a bit depth that supports the number of colors or shades of gray in your displayed figure.
Each graphics format can produce color, grayscale, or monochrome output. Check the Graphics Format table to see the level of color support for each format type. To preserve the color in your exported file, you must select a color graphics format. Bit depth also affects color.
Simulink models can only be exported to EPS or a Ghostscript format. You can only use the print function to export a model, not the Export dialog box.
If you want to use a figure in a journal or other publication, use a format that enables you to set a high resolution, such as TIFF or EPS.
If you want to use a figure in a Web publication, use either the PNG or the JPEG format. If you need to save an image as a GIF file, you can use the imwrite function. You need to convert M-by-N-by-3 truecolor CData (such as the getframe function provides) to an M–by–N 8–bit array and a colormap in order to write a GIF. Alternatively, you can export your figure as a TIFF file and convert it to a GIF using another software application, or capture a figure as an image using a screen capture utility and save it in formats the utility supports.
The figure properties listed in this section are affected when you select a graphics format when exporting to a file or the Windows clipboard.
Ghostscript formats support a limited number of fonts. If you use an unsupported font, Courier is substituted. See PostScript and Ghostscript Supported Fonts for more information.
Generally, higher resolution means higher quality. Your choice of resolution should be based in part on the device to which you will ultimately print it. Experimentation with different resolution settings can be helpful.
You cannot change the resolution of a Ghostscript format. The resolution is low (72 dpi) and might not be appropriate for publications.
If you want to read an exported figure back into the MATLAB environment, it is best to use one of the built-in MATLAB formats. You should not use PostScript® or a proprietary format such as Adobe® Illustrator (.ai), Windows metafile (.emf), or portable document format (.pdf) files.
Bitmaps are preferable for high-complexity plots, where complexity is determined by the number of polygons, the number of polygons with interpolated shading, the number of markers, the presence of truecolor images, and other factors. An example of a high-complexity plot is a surface plot that uses interpolated shading.
Vector formats are preferable for most 2-D plots and for some low-complexity surface plots.
Surface lighting and transparency are only supported by bitmap graphics formats. If you use a vector format, the lighting and transparency disappear. Of the two renderers intended for bitmaps (OpenGL and Z-buffer) only OpenGL supports transparency.
Note If you export to an EPS (vector) file using the Painters renderer and include a TIFF preview, the preview image is a bitmap and shows lighting or transparency when displayed on your screen. Remember that the underlying format vector file, which is what normally gets printed, does not support these features.
Generally, vector formats create better lines and text than bitmap formats. MATLAB renderers do not antialias lines or text.
In general, bitmap formats produce smaller files for complex plots than vector formats, and vector formats produce smaller files for simple plots than bitmap formats.
You can calculate the size of a figure exported to an uncompressed bitmap by multiplying the figure size by its resolution and the bit depth of the chosen format. For example, if a figure is 2 inches by 3 inches and has a resolution of 100 dpi (dots per inch), it will consist of (2x100)x(3x100), or 60,000 pixels. If exported to an 8-bit file, it uses 480,000 bits, or 60 KB. If exported to a 24-bit file, it uses three times the number of bytes, or 180 KB.
Vector format file size is affected by the complexity and number of objects in your figure. As the complexity and number of objects increase, the number of drawing commands increases.
You can resize a vector graphics figure after importing it into another software application without losing quality. (Not all applications that support vector formats enable you to resize them.)
This is not true of bitmap formats. Resizing a bitmap causes round-off errors that result in jagged edges and degradation of picture quality. This degradation is particularly obvious in lines and text and is highly discouraged.
The Graphics Format table on the print reference page indicates the color support and bit depth of each format. If file size is not critical, make sure you choose a format with a bit depth that supports the number of colors or shades of gray in your displayed figure.
If you specify a bitmap format when exporting, the exported file always contains a bitmap regardless of your current renderer setting. If you have the renderer set to Painters, which normally produces a vector format, that setting is ignored under these circumstances.
Vector format files, however, can store your figure as a vector or bitmap graphic depending on the renderer used to export it. If you do not specify a rendering method and OpenGL or Z-buffer is chosen automatically, your exported vector file contains a bitmap. If you want your figure exported as a vector graphic, be sure to set the rendering method to Painter's.
This section contains details about some of the export file formats MATLAB supports. For information about formats not listed here, consult a graphics file format reference.
Formats covered in this section are
Adobe Illustrator (ILL) is a vector format that is fully compatible with Adobe Illustrator software. An Illustrator file created in MATLAB can be further processed with Adobe Illustrator running on any platform. (When you view it in Illustrator, it has no template.)
By default, Illustrator files are color and saved in portrait orientation. The Illustrator group command is used to give the illustrations a hierarchy similar to that of the Handle Graphics® or Simulink graphic.
Some limitations of the Illustrator format are
Interpolated patches and surfaces cannot be created. The color of each polygon is determined by the average of the CData values for all of the polygon's vertices.
Images cannot be exported in this format.
The resolution setting of 72 dpi cannot be changed.
No fonts are downloaded to the Illustrator file. Any unavailable fonts are replaced with fonts that are available.
Enhanced Metafiles (EMF) are vector files similar in nature to Encapsulated PostScript (EPS), capable of producing near publication-quality graphics. EMF is an excellent format to use if you plan to import your image into a Microsoft® application and want the flexibility to edit and resize your image once it has been imported. It is the only supported MATLAB vector format you can edit from within a Microsoft application. (Your editing ability is limited. For the best results, do all your editing in Microsoft.)
A drawback of using EMF files is that they are generally only supported by Windows based applications.
The Encapsulated PostScript (EPS) vector format is the most reliable and consistent file format that MATLAB printing and export supports. It is widely recognized in desktop publishing and word processing packages on both UNIX® and Windows platforms. EPS is the only MATLAB supported export format that can produce CMYK output. (PostScript printer drivers also support this feature.)
This format is your best choice for producing publication-quality graphics. It might not be appropriate for figures containing interpolated shading because it creates a very large file that is difficult to print. For such figures, use the TIFF format with a high-resolution setting. For more information about format choices, see Choosing Bitmap or Vector Graphic Output.
When imported into Microsoft applications, an EPS file does not display unless you add a TIFF preview image to it.
The preview image is simple to add (see the next section, "Creating a Preview Image"). However, if you print your file to a non-PostScript printer, the TIFF preview is used as the printed image. The resolution of the preview image is 72 dpi, resulting in much lower quality than the EPS image. If there is no preview image, your printout to a non-PostScript printer contains an error message in place of the graphic. Many high-end graphics packages, like Adobe Illustrator, can print an EPS file to a non-PostScript printer.
You cannot edit figures when using EPS files in Microsoft applications; they can only be annotated.
Note The best vector format to use with Microsoft applications is EMF. See EMF Files.
EPS format has limited font support. When you export a graphic to the EPS file format, no attempt is made to determine whether the fonts you have used in your axes text objects are supported by the EPS format. Unsupported fonts are replaced with Courier.
Creating a Preview Image. You cannot create TIFF preview images using the graphical user interface. Use the print command with the -tiff switch. For example, to create an EPS Level 2 image with TIFF preview in file myfile.eps, type
print -depsc2 -tiff myfile.eps
The Tagged Image File Format (TIFF) is a very widely used bitmap format and can produce publication-quality graphics if you use a high-resolution setting (such as 200 or 300 dpi).
TIFF is a good format to choose if you are not sure what formats your target application supports, or if you want to import the graphic into more than one application without having to export it to several different formats. It can also be imported into most image-processing applications and converted to other formats, if necessary. For example, the print command does not produce GIF files, but there are many applications that can convert TIFF files to GIF. You can also use getframe to create a snapshot of a figure and imwrite to save that image as a GIF file.
The Joint Photographic Experts Group (JPEG) bitmap format is one of the dominant formats used in Web graphics. The 24-bit version that MATLAB supports carries more color information than the popular GIF format.
JPEG files always use JPEG compression. This is a lossy compression scheme, meaning that some data is thrown away during compression. When you export to a JPEG image, you can set the amount of compression to use. The more compression you use, the more data is thrown away. The compression amount is referred to as JPEG quality, where the highest setting results in the highest quality image, but the lowest amount of compression.
Setting JPEG Quality. You cannot set the quality using the graphical user interface. Use the print command with the -djpeg format switch, including the desired quality value as a suffix. This example exports to a JPEG file using a quality setting of 100.
print -djpeg100 myfile.jpg
By default, a quality setting of 75 is used. Possible values are from 1 to 100. The highest setting of 100 still results in some data loss, although the result is usually visually indistinguishable from the original.
To select a graphics format to use when exporting, choose a format from the Graphics Format table on the print reference page, and specify that format in either the Export dialog box or in the MATLAB print function.
When exporting your figure to a file:
To specify a nondefault graphics format for the figure you are exporting, include the -d switch with the print command. For example, to export the current figure to file spline2d.eps, with 600 dpi resolution, and using the EPS color graphics format, type
print -r600 -depsc spline2d