Documentation Center

  • Trial Software
  • Product Updates

How to Print or Export

Using Print Preview

Before you print or export a figure, preview the image by selecting Print Preview from the figure window's File menu. If necessary, you can use the set function to adjust specific characteristics of the printed or exported figure. Adjustments that you make in the Print Preview dialog also set figure properties; these changes can affect the output you get should you print the figure later with the print command. See Changing a Figure's Settings for details.

Adding a Header to the Printed Page

You can add a header to the page you are about to print by clicking the Lines/Text tab at the top of the Print Preview dialog box. At the bottom of that panel are the Header controls, as shown here:

The print header includes any text you want to appear at the top of the printed page. It can also include the current date. In the Header Text edit box, enter the text of the header. Under Date Type, select from a number of possible formats with which to display the current date and/or time. The default is to include no date. Click the Font button to change the font, font style, font size, or script type for the header text and date format. If you don't see the header as you specified it, click the Refresh button over the preview pane. A page containing a header plus date in bold italics is shown in the preview below:

Click Print to open the standard print dialog box to print the page. Click Close to close the dialog box and apply these settings to your figure.

Printing a Figure

This section tells you how to print your figure to a printer:

Printing with the Print GUI on Microsoft Windows

MATLAB® printing on Windows® platforms uses the standard Windows Print dialog box, which most Windows software products share. To open the Windows Print dialog box, select Print from the figure window's File menu or click the Print button in the Print Preview dialog box.

  • To print a figure, first select a printer from the list box, then click OK.

  • To save it to a file, click the Print to file check box, click OK, and when the Print to File window appears, enter the filename you want to save the figure to. The file is written to your current working folder.

Settings you can change in the Windows Print dialog box are as follows:

Properties.  To make changes to settings specific to a printer, click the Properties button. This opens the Windows Document Properties window.

Print range.  You can only select All in this panel. The selection does not affect your printed output.

Copies.  Enter the number of copies you want to print.

You can also open the Print dialog programmatically via the printdlg function.

Printing with the Print GUI on UNIX Platforms

MATLAB printing on UNIX® platrforms has a Print dialog box containing three tabs. To open the Print dialog box, select Print from the figure window's File menu. It opens showing the General tab's contents:

To print a figure, click the Name button under Print Service and select a printer from the list box.

    Note:   Printers accessed from the Print dialog are assumed to be PostScript®-enabled. If you want to print to a non-PostScript device, you will need to use File > Save As and specify the Save as type or issue a print command specifying the appropriate driver with the -d flag.

The Page Setup tab on the Print dialog looks like this:

You can set paper characteristics and margins with the controls on this tab. You might want to use the Print Preview dialog instead, however, as it allows you to do the same things and gives you visual feedback at the same time. For details, see Using Print Preview.

The Appearance Print dialog tab lets you control several aspects of your print jobs:

The Appearance options include Duplex and Tumble printing, whether a banner page should precede the printed page, whether to print in color, and what quality of printing to use. You can also use Print Preview to control color.

Related settings in the Print Preview dialog box include

Printing in Color.  Depending on the capabilities of the printer you are using, you can print in black and white, grayscale, or color by selecting the appropriate button in the Color Scale panel of the Print Preview Color tab. You can also choose a background color that is the same or different from the figure's color.

Figure Size and Position on Printed Page.  If you want the printed plot to have the same size as it does on your screen, select Auto (Actual Size, Centered) on the Layout tab. If you want the printed output to have a specific size, select Use manual size and position.

See Setting the Figure Size and Position for more information.

Axes Limits and Ticks.  To force the same number of ticks and the same limit values for the axes as are used on the screen to be printed, select Keep screen limits and ticks on the Advanced tab of the Print Preview dialog box. To automatically scale the limits and ticks of the axes based on the size of the printed figure, select Recompute limits and ticks.

See Setting the Axes Ticks and Limits for more information.

Printing Using PostScript Commands

Use the print function to print from the PostScript command line or from a program. See Printing and Exporting with print for more information.

To send the current or most recently active figure to a printer, simply type

print

The Printing Options table on the print reference page shows a full list of options that you can use with the print function. For example, the following command prints Figure No. 2 with 600 dpi resolution, using the Canon® BubbleJet BJ200 printer driver:

print -f2 -r600 -dbj200

Printing to a File

Instead of sending your figure to the printer right now, you have the option of "printing" it to a file, and then sending the file to the printer later on. You can also append additional figures to the same file using the print command.

    Note:   When you print to a file, the file name must have fewer than 128 characters, including path name. When you print to a file in your current folder, the filename must have fewer than 126 characters, because MATLAB places './' or '.\'' at the beginning of the filename when referring to it.

This section tells you how to save your figure to a file:

Printing to a File with the Print GUI on Windows Platforms

  1. To open the Print dialog box, select Print from the figure window's File menu.

  2. Select the check box labeled Print to file, and click the OK button.

  3. The Print to file dialog box appears, allowing you to specify the output folder and filename.

Printing to a File with the Print GUI on UNIX Platforms

  1. To open the Print dialog box, select Print from the figure window's File menu.

  2. Select the radio button labeled File, and either fill in or browse for the folder and filename.

Printing to a File Using MATLAB Commands

To print the figure to a PostScript file, type

print filename

If you don't specify the filename extension, MATLAB uses an extension that is appropriate for the print driver being used.

You can also include an -options argument when printing to a file. For example, to append the current figure to an existing file, type

print -append filename

The only way to append to a file is by using the print function. There is no dialog box that enables you to do this.

    Note   If you print a figure to a file, the file can only be printed and cannot be imported into another application. If you want to create a figure file that you can import into an application, see the next section, "Exporting to a File"

Appending Additional Figures to a File.  Once you have printed one figure to a PostScript file, you can append other figures to that same file using the -append option of the print function. You can only append using the print function.

This example prints Figure No. 2 to PostScript file myfile.ps, and then appends Figure No. 3 to the end of the same file:

print -f2 myfile
print -f3 -append myfile

Exporting to a File

Export a figure in a graphics format to a file if you want to import it into another application, such as a word processor. You can export to a file from the Windows or UNIX Export Setup dialog box or from the command line.

This section tells you how to export your figure to a file:

It also covers

For further information, see Choosing a Graphics Format.

    Note:   When you export to a file, the file name must have fewer than 128 characters, including path name. When you print to a file in your current folder, the filename must have fewer than 126 characters, because MATLAB places './' or '.\'' at the beginning of the filename when referring to it.

Using the Export Setup GUI

The Export Setup GUI appears when you select Export Setup from the File menu of a figure window. This GUI has four dialog boxes that enable you to adjust the size, rendering, font, and line appearance of your figure prior to exporting it. You select each of these dialog boxes by clicking Size, Rendering, Fonts, or Lines from theProperties list. For a description of each dialog box, see

Adjusting the Figure Size

Click Size in the Export Setup dialog box to display this dialog box.

The Size dialog box modifies the size of the figure as it will appear when imported from the export file into your application. If you leave the Width and Height settings on auto, the figure remains the same size as it appears on your screen. You can change the size of the figure by entering new values in the Width and Height text boxes and then clicking Apply to Figure. To go back to the original settings, click Restore Figure.

To save any settings that you change, or to load settings that you used earlier, see Saving and Loading Settings.

Changing the Rendering

Click Rendering in the Export Setup dialog box to display this dialog box.

You can change the settings in this dialog box as follows:

Colorspace.  Use the drop-down list to select a colorspace. Your choices are

  • Black and white

  • Grayscale

  • RGB color

  • CMYK color

Custom Color.  Click the check box and enter a color to be used for the figure background. Valid entries are

  • white, yellow, magenta, red, cyan, green, blue, or black

  • Abbreviated name for the same colors — w, y, m, r, c, g, b, k

  • Three-element RGB value — See the help for colorspec for valid values. Examples: [1 0 1] is magenta. [0 .5 .4] is a dark shade of green.

Custom Renderer.  Click the check box and select a renderer from the drop-down list:

  • painters (vector format)

  • OpenGL (bitmap format)

  • Z-buffer (bitmap format)

Resolution.  You can select one of the following from the drop-down list:

  • Screen — The same resolution as used on your screen display

  • A specific numeric setting — 150, 300, or 600 dpi

  • auto — UNIX selects a suitable setting

Keep axis limits.  Click the check box to keep axis tick marks and limits as shown. If unchecked, automatically adjust depending on figure size.

Show uicontrols.  Click the check box to show all user interface controls in the figure. If unchecked, hide user interface controls.

Changing Font Characteristics

Click Fonts in the Export Setup dialog box to display this dialog box.

You can change the settings in this dialog box as follows:

Custom Size.  Click the check box and use the radio buttons to select a relative or absolute font size for text in the figure.

  • Scale font by N % — Increases or decreases the size of all fonts by a relative amount, N percent. Enter the word auto to automatically select the appropriate font size.

  • With minimum of N points — You can specify a minimum font size when scaling the font by a percentage.

  • Use fixed font size N points — Sets the size of all fonts to an absolute value, N points.

Custom Name.  Click the check box and use the drop-down list to select a font name from those offered in the drop-down list.

Custom Weight.  Click the check box and use the drop-down list to select the weight or thickness to be applied to text in the figure. Choose from normal, light, demi, or bold.

Custom Angle.  Click the check box and use the drop-down list to select the angle to be applied to text in the figure. Choose from normal, italic, or oblique.

Changing Line Characteristics

Click Lines in the Export Setup dialog box to display this dialog box.

You can change the settings in this dialog box as follows:

Custom width.  Click the check box and use the radio buttons to select a relative or absolute line size for the figure.

  • Scale line width by N % — Increases or decreases the width of all lines by a relative amount, N percent. Enter the word auto to automatically select the appropriate line width.

  • With minimum of N points — Specify a minimum line width when scaling the font by a percentage.

  • Use fixed line width N points — Sets the width of all lines to an absolute value, N points.

Convert solid lines to cycle through line styles.  When colored graphics are imported into an application that does not support color, lines that could formerly be distinguished by unique color are likely to appear the same. For example, a red line that shows an input level and a blue line showing output both appear as black when imported into an application that does not support colored graphics.

Clicking this check box causes exported lines to have different line styles, such as solid, dotted, or dashed lines rather than differentiating between lines based on color.

Saving and Loading Settings

If you think you might use these export settings at another time, you can save them now and reload them later. At the bottom of each Export Setup dialog box, there is a panel labeled Export Styles. To save your current export styles, type a name into the Save as style named text box, and then click Save.

If you then click the Load settings from drop-down list, the name of the style you just saved appears among the choices of export styles you can load. To load a style, select one of the choices from this list and then click Load.

To delete any style you no longer have use for, select that style name from the Delete a style drop-down list and click Delete.

Exporting the Figure

When you finish setting the export style for your figure, you can export the figure to a file by clicking the Export button on the right side of any of the four Export Setup dialog boxes. As new window labeled Save As opens.

Select a folder to save the file in from the Save in list at the top. Select a file type for your file from the Save as type drop-down list at the bottom, and then enter a file name in the File name text box. Click the Save button to export the file.

For information on the graphics file formats supported by MATLAB, see Choosing a Graphics Format.

Exporting Using MATLAB Commands

Use the print function to print from the MATLAB command line or from a program. See Printing and Exporting with print for basic information on printing from the command line.

To export the current or most recently active figure, type

print -dfileformat filename

where fileformat is a supported graphics format and filename is the name you want to give to the export file. MATLAB selects the filename extension, if you don't specify it.

You can also specify a number of options with the print function. These are shown in the Printing Options table on the print reference page.

For example, to export Figure No. 2 to file spline2d.eps, with 600 dpi resolution and using the EPS color graphics format, type

print -f2 -r600 -depsc spline2d

Graphics file formats are explained in more detail in the sections Choosing a Graphics Format and Description of Selected Graphics Formats.

Exporting with getframe

You can use the getframe function with imwrite to export a graphic. getframe is often used in a loop to get a series of frames (figures) with the intention of creating a movie. No matter what the intrinsic resolution of the graphics might be, getframe only captures them at screen resolution.

Some of the benefits of using this export method over using print are

  • You can use getframe to capture a portion of the figure, rather than the whole figure.

  • imwrite offers greater flexibility for setting format-specific options, such as the bit depth and compression.

The drawbacks of using this method are

  • imwrite uses built-in MATLAB formats only

  • getframe and imwrite are limited to screen resolution

.Consequently, you do not have access to the Ghostscript formats available to you when exporting with the print function or Export menu.

How to Use getframe and imwrite.  Use getframe to capture a figure and imwrite to save it to a file. getframe returns a structure containing the fields cdata and colormap. The colormap field is empty on true color displays. The following example captures the current figure and exports it to a PNG file.

I = getframe(gcf);
imwrite(I.cdata, 'myplot.png');

You should use the proper syntax of imwrite for the type of image captured. In the example above, the image is captured from a true color display. Because the colormap field is empty, it is not passed to imwrite.

Example — Exporting a Figure Using getframe and imwrite.  This example offers device independence—it works for either RGB-mode or indexed-mode monitors.

X=getframe(gcf);
if isempty(X.colormap)
   imwrite(X.cdata, 'myplot.bmp')
else
   imwrite(X.cdata, X.colormap, 'myplot.tif')
end

For information about available file formats and format-specific options, see the imwrite function reference page. For information about creating a movie from a series of frames, see Animation.

Saving Multiple Figures to an AVI File

You can also save multiple figures to an AVI file using the MATLAB VideoWriter. AVI files can be used for animated sequences and do not need MATLAB to run, but do require an AVI viewer. For more information, see Export to Audio and Video.

Importing MATLAB Graphics into Other Applications

You can include MATLAB graphics in a wide variety of applications for word processing, slide preparation, modification by a graphics program, presentation on the Internet, and so on. In general, the process is the same for all applications:

  1. Use MATLAB graphics to create the figure you want to import into another application.

  2. Export the MATLAB figure to one of the supported graphics file formats, selecting a format that is both appropriate for the type of figure and supported by the target application. See Choosing a Graphics Format for help.

  3. Use the import features of the target application to import the graphics file.

Edit Before You Export.  Vector graphics may be fully editable in a few high-end applications, but most applications do not support editing beyond simple resizing. Bitmaps cannot be edited with quality results unless you use a software package devoted to image processing. In general, you should try to make all the necessary settings while your figure is still in MATLAB.

Importing into Microsoft Applications.  To import your exported figure into a Microsoft® application, select Picture from the Insert menu. Then select From File and navigate to your exported file. If you use the clipboard to perform your export operations, you can take advantage of the recommended MATLAB settings for Microsoft Word and PowerPoint®.

Example — Importing an EPS Graphic into LaTeX.  This example shows how to import an EPS file named peaks.eps into LaTeX.

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\begin{figure}[h]
\centerline{\includegraphics[height=10cm]{peaks.eps}}
\caption{Surface Plot of Peaks}
\end{figure}

\end{document}

EPS graphics can be edited after being imported to LaTeX. For example, you can specify the height in any LaTeX-compatible dimension. To set the height to 3.5 inches, use the command

height=3.5in

You can use the angle function to rotate the graph. For example, to rotate the graph 90 degrees, add

angle=90

to the same line of code that sets the height, i.e., [height=10cm,angle=90].

Exporting to the Windows or Macintosh Clipboard

You can export a figure to the Windows or Macintosh clipboard. The formats used are discussed below.

Windows Clipboard Format

You can copy graphic data to the system clipboard data on Windows in either of two graphics formats: EMF color vector or BMP 8-bit color bitmap.

By default, the graphics format is automatically selected for you, based on the rendering method used to display the figure. For figures rendered with OpenGL® or Z-buffer, MATLAB uses the BMP format. For figures rendered with Painter's, the EMF format is used. For information about how rendering methods are chosen, see The Default MATLAB Renderer.

To override the automatic selection, specify the format of your choice using either the Windows Copy Options Preferences dialog box, or the -d switch in the print command.

Macintosh Clipboard Format

On Macintosh platforms (using Java® figures, the default), MATLAB copies figures to other applications in a high-resolution PDF format. If the figure contains uicontrols, then MATLAB uses a TIFF format instead. Use Edit > Copy Figure to copy to the clipboard, not the print command. The entire figure window is captured.

Exporting to the Clipboard Using GUIs

Before you export the figure to the clipboard, you can use the Copy Options Preferences dialog box to select a nondefault graphics format, or to adjust certain figure settings. These settings become the new defaults for all figures exported to the clipboard.

    Note   When exporting to the clipboard in Windows metafile format (e.g., print -dmeta), the settings from the figure Copy Options Preferences template are ignored.

To open the Copy Options Preferences dialog box, select Copy Options from the figure window's Edit menu. Any changes you make with this dialog box affect only the clipboard copy of the figure; they do not affect the way the figure looks on the screen.

Settings you can change in the Copy Options Preferences dialog box are as follows:

Clipboard format.  

  • To copy the figure in EMF color vector format, select Metafile. This option places a metafile on the system clipboard. If the figure uses features that are not supported by the painters renderer, such as lighting or transparency, then the metafile copied to the clipboard will contain a bitmap representation of the figure; otherwise the metafile copied to the clipboard will contain a vector representation of the figure.

  • To automatically select the format for you, select Preserve information. The "metafile if possible" path looks to see if the figure is using any renderer features that are not supported by painters, such as lighting or transparency. If it uses those features MATLAB generates a bitmap; if it only uses painters features, MATLAB generates a metafile. MATLAB clipboard data uses the metafile format whenever possible.

  • To use BMP 8-bit color bitmap format, select Bitmap.

    Note:   On Macintosh platforms, the Copy Options dialog box does not have the Clipboard format options.

Figure background color.  To keep the background color the same as it appears on the screen, select Use figure color. To make the background white, select Force white background. For a background that is transparent, for example, a slide background to frame the axes part of a figure, select Transparent background.

Size.  Select Match figure screen size to copy the figure as it appears on the screen, or leave it unselected to use the Width and height options in the Export Setup dialog to determine its size.

  1. Open the Copy Options Preferences dialog box if you need to make any changes to those preferences used in copying to the clipboard.

  2. Click OK to see the new preferences. These will be used for all future figures exported to the clipboard.

  3. Select Copy Figure from the figure window's Edit menu to copy the figure to the clipboard.

Exporting to the Clipboard Using MATLAB Commands

Export to the clipboard on Windows using the print function with a graphics format, but no filename. You must use one of the following clipboard formats: -dbitmap or -dmeta. These switches create a Windows bitmap (BMP) or an enhanced metafile (EMF), respectively.

For example, to export the current figure to the clipboard in enhanced metafile format, type

print -dmeta

    Note   When printing, the print -d option specifies a printer driver. When exporting, the print -d option specifies a graphics format.

    You cannot use print -d to export graphics to a Macintosh system clipboard.

Was this topic helpful?