Troubleshooting

Introduction

This section describes some common problems you might encounter when printing or exporting your figure. If you don't find your problem listed here, try searching the Knowledge Base maintained by MathWorks® Technical Support Department. Go to http://www.mathworks.com/support and enter a topic in the search field.

Printing Problems

Printer Drivers

I am using a Windows® printer driver and encountering problems such as segmentation violations, general protection faults, application errors, and unexpected output.

Try one of the following solutions:

  • Check the table of drivers in the print reference page to see if there are other drivers you can try.

  • Contact the printer vendor to obtain a different native printer driver. The behavior you are experiencing might occur only with certain versions of the native printer driver. If this doesn't help and you are on a Windows system, try reinstalling the drivers that were shipped with your Windows installation disk.

  • Export the figure to a graphics-format file, and then import it into another application before printing it. For information about exporting MATLAB® figures, see Exporting to a File.

PostScript Output

When I use the print function with the -deps switch, I receive this error message.

Encapsulated PostScript files cannot be sent to the printer. 
File saved to disk under name 'figure2.eps'

As the error message indicates, your figure was saved to a file. EPS is a graphics file format and cannot be sent to a printer using a printer driver. To send your figure directly to a printer, try using one of the PostScript® driver switches. See the table of drivers in the print reference page. To print an EPS file, you must first import it into a word processor or other software program.

Default Settings

My printer uses a different default paper type than the MATLAB default type of letter. How can I change the default paper type so that I don't have to set it for each new figure?

You can set the default value for any property by adding a line to startup.m. Adding the following line sets the default paper type to A4.

set(0,'DefaultFigurePaperType','A4'); 

In your call to set, combine the word Default with the name of the object Figure and the property name PaperType.

I set the paper orientation to landscape, but each time I go to print a new figure, the orientation setting is portrait again. How can I change the default orientation so that I won't have to set it for each new figure?

See the explanation for the previous question. Adding the following line to startup.m sets the default paper orientation to landscape.

set(0,'DefaultFigurePaperOrient','landscape')

Color vs. Black and White

I want the lines in my figure to print in black, but they keep printing in color.

You must be using a color printer driver. You can specify a black-and-white driver using the print function or the Print Preview dialog box to force the lines for the current figure to print in black. See Setting the Line and Text Color for instructions.

A white line in my figure keeps coming out black when I print it.

There are two things that can cause this to happen. Most likely, the line is positioned over a dark background. The MATLAB default is to invert your background to white when you print, and changes any white lines over the background to black. To avoid this, retain your background color when you print. See Setting the Background Color.

The other possibility is that you are using a Windows printer driver and the printer is sending inaccurate color information to MATLAB.

I am using a color printer, but my figure keeps printing in black and white.

By default, MATLAB uses a black-and-white printer driver. You need to specify a color printer driver.

Printer Selection

I have more than one printer connected to my system. How do I specify which one to print my figure with?

You can use either the Print dialog box, or the MATLAB print function, specifying the printer with the -P switch. For instructions using either method, see Selecting the Printer.

Rotated Text

I have some rotated text in my figure. It looks fine on the screen, but when I print it, the resolution is poor.

You are probably using bitmapped fonts, which don't rotate well. Try using TrueType fonts instead.

SizeChangedFcn Warning

I get a warning about my SizeChangedFcn being used when I print my figure.

By default, MATLAB resizes your figure when converting it to printer coordinates. That means it calls any SizeChangedFcn you have created for the figure and issues a warning. You can avoid this warning by setting the figure to print at screen size.

Improper Printer Configuration

I get the following error message on my LINUX/UNIX system ‘Printing failure. There are no properly configured printers on the system.'

This might be a problem with the location of the lpc command on your system. If not present, create a symbolic link from /usr/sbin/lpc to wherever the lpc command resides on your system.

Exporting Problems

Background Color

I generated a figure with a black background and selected "Use figure color" from the Copy Options panel of the Preferences dialog box. But when I exported my figure, its background was changed to white.

You must have exported your figure to a file. The settings in Copy Options only apply to figures copied to the clipboard.

There are two ways to retain the displayed background color: use the Print Preview dialog box or set the InvertHardCopy property to off. See Setting the Background Color for instructions on either method.

Default Settings

I want to export all of my figures using the same size. Is there some way to do this so that I don't have to set the size for each individual figure?

You can set the default value for any property by adding a line to startup.m. Adding the following line sets the default figure size to 4-by-3 inches.

set(0,'DefaultFigurePaperPosition',[0 0 4 3]); 

In your call to set, combine the word Default with the name of the object Figure and the property name PaperPosition.

I use the clipboard to export my figures as metafiles. Is there some way to force all of my copy operations to use the metafile format?

On Windows systems, use the Copy Options panel of the Preferences dialog box. Any settings made here, including whether your figure is copied as a metafile or bitmap, apply to all copy operations. See Exporting to the Windows or Macintosh Clipboard for instructions.

Microsoft Word

I exported my figure to an EPS file, and then tried to import it into my Word document. My printout has an empty frame with an error message saying that my EPS picture was not saved with a preview and will only print to a PostScript printer. How do I include a TIFF preview?

Use the print command with the -tiff switch. For example,

print -deps -tiff filename

If you print to a non-PostScript printer with Word, the preview image is used for printing. This is a low-resolution image that lacks the quality of an EPS graphic.

When I try to resize my figure in Word, its quality suffers.

You must have used a bitmap format. Bitmap files generally do not resize well. If you are going to export using a bitmap format, try to set the figure's size while it's still in MATLAB. See Setting the Figure Size and Position for instructions.

As an alternative, you can use one of the vector formats, EMF or EPS. Figures exported in these formats can be resized in Word without affecting quality.

I exported my figure as an EMF to the clipboard. When I paste it into Word, some of the labels are printed incorrectly.

This problem occurs with some Microsoft® Word and Windows versions. Try editing the labels in Word.

File Format

I tried to import my exported figure into a word processing document, but I got an error saying the file format is unrecognized.

There are two likely causes: you used the print function and forgot to specify the export format, or your word processing program does not support the export format. Include a format switch when you use the print function; simply including the file extension is not sufficient. For instructions, see Exporting to a File.

If this does not solve your problem, check what formats the word processor supports.

I tried to append a figure to an EPS file, and received an error message

You cannot append figures to an EPS file. The -append option is only valid for PostScript files, which should not be confused with EPS files. PostScript is a printer driver; EPS is a graphics file format.

Of the supported export formats, only HDF supports storing multiple figures, but you must use the imwrite function to append them. For an example, see the reference page for imwrite.

Size of Exported File

I've always used the EPS format to export my figures, but recently it started to generate huge files. Some of my files are now several megabytes!

Your graphics have probably become complicated enough that MATLAB is using the OpenGL® renderer instead of the Painter's renderer. It does this to improve display time or to handle attributes that Painter's cannot, such as lighting. However, using OpenGL causes a bitmap to be stored in your EPS file, which with large figures leads to a large file.

There are two ways to fix the problem. You can specify the Painter's renderer when you export to EPS, or you can use a bitmap format, such as TIFF. The best renderer and type of format to use depend upon the figure. For information about the rendering methods and how to set them, see Selecting a Renderer.

Making Movies

I am using MATLAB functions to process a large number of frames. I would like these frames to be saved as individual files for later conversion into a movie. How can I do this?

Use getframe to capture the frames, imwrite to write them to a file, and movie to create a movie from the files. For more information about creating a movie from the captured frames, see the reference page for movie.

You can also save multiple figures to an AVI file. AVI files can be used for animated sequences that do not need MATLAB to run. However, they do require an AVI viewer. For more information, see Export to Audio and Video in the MATLAB Programming Fundamentals documentation.

Extended Operations

There are some export operations that cannot be performed using the Export dialog box.

You need to use the print function to do any of the following operations:

  • Export to a supported file format not listed in the Export dialog box. The formats not available from the Export dialog box include HDF, some variations of BMP and PCX, and the raw data versions of PBM, PGM, and PPM.

  • Specify a resolution.

  • Specify one of the following options:

    • TIFF preview

    • Loose bounding box for EPS files

    • Compression quality for JPEG files

    • CMYK output on Windows platforms

  • Perform batch exporting.

General Problems

Background Color

When I output my figure, its background is changed to white. How can I get it to have the displayed background color?

By default, when you print or export a figure, the background color inverts to white. There are two ways to retain the displayed background color: use the Print Preview dialog box or set the InvertHardCopy property to off. See Setting the Background Color for instructions on either method.

If you are exporting your figure to the clipboard, you can also use the Copy Options panel of the Preferences dialog box. Setting the background here sets it for all figures copied to the clipboard.

Default Settings

I need to produce diagrams for publications. There is a list of requirements that I must meet for size of the figure, fonts types, etc. How can I do this easily and consistently?

You can set the default value for any property by adding a line to startup.m. As an example, the following line sets the default axes label font size to 12.

set(0,'DefaultAxesFontSize',12);

In your call to set, combine the word Default with the name of the object Axes and the property name FontSize.

Dimensions of Output

The dimensions of my output are huge. How can I make it smaller?

Check your settings for figure size and resolution, both of which affect the output dimensions of your figure.

The default figure size is 8-by-6 inches. You can use the Print Preview dialog box or the PaperPosition property to set the figure size. See Setting the Figure Size and Position.

The default resolution depends on the export format or printer driver used. For example, built-in MATLAB bitmap formats, like TIFF, have a default resolution of 150 dpi. You can change the resolution by using the print function and the -r switch. For default resolution values and instructions on how to change them, see Setting the Resolution.

I selected "Auto (actual size, centered)" from the Print Preview menu, but my output looks a little bigger, and my font looks different.

You probably output your figure using a higher resolution than your screen uses. Set your resolution to be the same as the screen's.

As an alternative, if you are exporting your figure, see if your application enables you to select a resolution. If so, import the figure at the same resolution it was exported with. For more information about resolution and how to set it when exporting, see Setting the Resolution.

Axis and Tick Labels

When I resize my figure below a certain size, my x-axis label and the bottom half of the x-axis tick labels are missing from the output.

Your figure size might be too small to accommodate the labels. Labels are positioned a fixed distance from the x-axis. Since the x-axis itself is positioned a relative distance away from the window's edge, the label text might not fit. Try using a larger figure size or smaller fonts. For instructions on setting the size of your figure, see Setting the Figure Size and Position. For information about setting font size, see the Text Properties properties page.

In my output, the x-axis has fewer ticks than it did on the screen.

MATLAB has rescaled your ticks because the size of your output figure is different from its displayed size. There are two ways to prevent this: select Keep screen limits and ticks from the Advanced tab of the Print Preview dialog box, or set the XTickMode, YTickMode, and ZTickMode properties to manual. See Setting the Axes Ticks and Limits for details.

UI Controls

My figure contains UI controls. How do I prevent them from appearing in my output?

Use the print function with the -noui switch. For details, see Excluding User Interface Controls from Printed Output.

Cropping

I can't output my figure using the uncropped setting (i.e., a loose BoundingBox).

Only PostScript printer drivers and the EPS export format support uncropped output. There is a workaround for Windows printer drivers, however. Using the print function, save your figure to a file that can be printed later. For an example see Producing Uncropped Figures.

Text Object Font

I have a problem with text objects when printing with a PostScript printer driver or exporting to EPS. The fonts are correct on the screen, but are changed in the output.

You have probably used a font that is not supported by EPS and PostScript. All unsupported fonts are converted to Courier.

Printing and Exporting Graphs with Legends

Why does the legend appear in a different location when I set legend Location to Best or BestOutside?

When you print or export a graph containing a legend that you placed in the figure using the Location option set to Best or BestOutside, MATLAB can reposition the legend in the output. This repositioning happens because the process of printing or exporting a figure can result in changes to certain properties that affect the choice of legend location.

To avoid potential repositioning of the legend in printed or exported output, set the legend position explicitly with a four-element vector. For more information on legend position, see the legend function.

Was this topic helpful?