File Exchange

image thumbnail


version 3.11 (96.7 KB) by Yair Altman
Exports figures nicely to a number of vector & bitmap formats


Updated 30 Jul 2020

GitHub view license on GitHub

Editor's Note: Popular File 2011 2012 2013 2014 2015 2016 2017 2018

This file was selected as MATLAB Central Pick of the Week

This function saves a figure or single axes to one or more vector and/or bitmap file formats, and/or outputs a rasterized version to the workspace, with the following properties:
- Figure/axes reproduced as it appears on screen
- Cropped/padded borders (optional)
- Embedded fonts (pdf only)
- Improved line and grid line styles
- Anti-aliased graphics (bitmap formats)
- Render images at native resolution (optional for bitmap formats)
- Transparent background supported (pdf, eps, png, tiff)
- Semi-transparent patch objects supported (png, tiff)
- RGB, CMYK or grayscale output (CMYK only with pdf, eps, tiff)
- Variable image compression, including lossless (pdf, eps, jpg)
- Optional rounded line-caps (pdf, eps)
- Optionally append to file (pdf, tiff)
- Vector formats: pdf, eps
- Bitmap formats: png, tiff, jpg, bmp, export to workspace

This function is especially suited to exporting figures for use in publications and presentations, because of the high quality and portability of media produced.

Note that the background color and figure dimensions are reproduced (the latter approximately, and ignoring cropping & magnification) in the output file. For transparent background (and semi-transparent patch objects), use the -transparent option, and set the axes 'Color' property to 'none' where desired. Pdf, eps and png are the only file formats to support a transparent background, while the png format alone supports transparency of patch objects.

When exporting to vector format (pdf & eps), and to bitmap using the painters renderer, this function requires that ghostscript is installed on your system. You can download this from:

When exporting to eps it additionally requires pdftops, part of the Xpdf package. You can download this from:

Usage examples and tips can be found in the README section at:

A technical description of the various components can be found here:

This submission was originally created by Oliver Woodford. Yair Altman maintains this utility since Jan 2015.

When reporting bugs, please raise an issue via GitHub:
Do not paste the error into the comments below - I will not respond to these.

Cite As

Yair Altman (2020). export_fig (, GitHub. Retrieved .

Comments and Ratings (1037)

J. T. Holmi

Yair, could you add a '-ignoreupdate' parameter to disable automatic "Warning: A newer version of export_fig is available."-messages? I wouldn't want to modify the export_fig code to disable it manually.

Jian Zhou

Has anyone seen this problem? - when the targetted eps file is very large, there is a significant drop of the resolution.

Great submission. Recently updated from 2015 version to 2020 version and noticed a really nice speed increase.

I would agree with Ander that the advertisement messages are at bit odd though. Huge toolboxes that take several people 1000s of hours of work do not include adverts coded into the functions. So by comparison your heated berating of Ander looks quite childish. I have also never seen another FEX submission that included adverts.

Do YOU want adverts in every FEX submission? What about pop-ups? Because you are setting that standard.

In my case the advert kept displaying, even though I think it is only supposed to display once. So I commented out the section within the if loop "if isempty(promo) && ~isdeployed"
I also commented out the section within the for loop "function displayMsg(params, funcName, type, filenameParam)"

Thank you very much. This really solved my problem of saving 3D figures as vector graphics. Since I'm using Windows 10 and Word, I'd like to save my figures as emf format. But I found the size of emf format is more than 20 times larger than svg. And texts in emf figure look not clear in Word. I'm using MATLAB 2019b, Word 2016


Tiago Dias

Incredible. Thank you. Quite useful for publication purposes.

thanks bro


I only had an issue with the grey background. For the solution used this: set(0,'DefaultFigureColor','remove')
Credits to the discussion here:


Amazing Submission.
Nevertheless I'm not able to save with transparency in "svg", "eps" or "pdf" with Matlab R2020a (MacOs).
I'm using the line set(gca,'Color','None') and export_fig('test.svg', '-transparent'), but I obtain a black backgrounded image.


A King

Thank you very much! This is really helpful function, and it works also with subplots.

Yair Altman

@GalWiner, @bstechel - Annotations with EdgeColor='none' work properly in R2019b and R2020a on my Windows 10 machine. If you still see a problem, open a new issue on

Harry Dymond

@Gal Winer, @bstechel - you have to set LineStyle to 'none' instead of setting its colour to 'none'
@Yair Altman - agreed about your comment to @Ander Biguri. I've been using your export_fig and many hints from undocumented MATLAB for years and I've never paid you a penny.
You could have kept all that info just in your book, and you didn't have to take over the maintenance of this indispensable tool. Many thanks to you for both of these!

Arash Azizi

Yair Altman

@Andar - REALLY?! you get a "Fantastic submission" (one that is the product of many hundreds of workhours) for *FREE* and you complain about a single unobtrusive ad and rate the submission with one star?! I bet you also complain about the ads in free phone apps and computer programs. Perhaps I should send you a free gold-engraved version? would that satisfy your ulterior morality? You selfish, ungrateful so-and-so - you make me sick!

Fantastic submission, but the "advertisement" when first run is uncalled for and in my opinion, not moraly OK.


@Gal Winer - did you/someone find a solution for the annotation textbox 'EdgeColor' problem?


Gal Winer

Hi Yair, thanks for this function.
i seem to have an issue with an annotation textbox. I set the 'EdgeColor' to 'none' but the PDF output has the border as black.
Is this a known issue and if so, is there a workaround?



Yair Altman

@Jan Vopel - ghostscript.m is part of the export_fig package. You need to install the entire export_fig package, not just append_pdf.m. Then ensure that the folder in which you installed export_fig is in your Matlab path.
@Sebastian, @Arnold, @Patrick - please submit an issue report on
@Rohit - export_fig does not copy graphic objects from one figure to another, it exports them to a separate file (PDF/JPG/etc.). Read the documentation for details.
@Jy Han - see also, try a newer version of export_fig, since this issue was partially resolved in recent weeks.

Jan Vopel

I want to use the append_pdfs.m function, so i installed ghostcript. Nevertheless the error "Unrecognized function or variable 'ghostscript'" occurs. I installed it on another drive than the one my workfile is in. Can anyone help me with this error, maybe you had the same error?
Many thanks in advance


Exporting a figure with many subplots to png, the function had issues with subplot positions: it moved them slightly, but enough to not look good. It came from the print2array function, which mysteriously affected the figure handle fig such that position shifted when later updating figure properties, e.g. when executing set(fig, 'Color', 'w', 'Position', pos);.

I circumvented the issue with the following. Before each print2array execution, do saveas(fig,'tmp'). After each print2array execution, delete(fig); fig = open('tmp.fig'). The draw back is that the handle fig changed, so I just have it as an output of print2array and update it in the parent function.

I would upload my edits, but I don't know how to :-(
Hope this help anyway !

I am using MATLAB 2019b app designer, I want to use export_fig to copy my Ui Axes to a figure. How this can be done?
will this work- export_fig(app.UiAxes,destination) ??

kors Atsua

Works very perfectly. Thanks


I have been looking for a way to keep the output of export_fig as 16bit, but all I can think of is either export to clipboard and then paste as a variable in a workspace or exporting as tmp.tif then imread('tmp.tif') it again and delete after. Both are quite error prone and not nice.
I'd appreciate a better way... like out = export_fig('16bit');


S. St.

I have a question about embedded fonts: I would like to use export_fig to create EPS figures without embedding the text into the file (i.e. I want to be able to edit the text afterward). Is this possible? Thanks.

Hello. Are there any limitations to export fig? I'm trying to make images of Q-criterion in fluid mechanics (which I imagine is a dense plot to make) and MATLAB doesn't write it using export fig and seems to get hung up. Thanks!


jy Han

Hi! I have questions in outputing pdfs using export_fig founction. I am very appretiate if you can answer this questions.The matlab reported errors as follows:
Error: /undefined in .setopacityalpha
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1990 1 3 %oparray_pop 1989 1 3 %oparray_pop 1988 1 3 %oparray_pop --nostringval-- 1977 1 3 %oparray_pop 1833 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:732/1123(ro)(G)-- --dict:0/20(G)-- --dict:131/200(L)--
Current allocation mode is local
Last OS error: Permission denied
Current file position is 9674487
GPL Ghostscript 9.50: Unrecoverable error, exit code 1

Ghostscript error: perhaps C:\Users\23181\AppData\Local\Temp\tpb4f71068_4603_4bb3_8d1f_50d514e8e4de.pdf is open by another application
or maybe you have another gs executable in your system's path

Ghostscript path: D:\Program Files\MATLAB\gs9.50\bin\gswin64c.exe
Ghostscript options: -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile="C:\Users\23181\AppData\Local\Temp\tpb4f71068_4603_4bb3_8d1f_50d514e8e4de.pdf" -dEPSCrop -sFONTPATH="C:\Windows\Fonts" -f "C:\Users\23181\AppData\Local\Temp\tp714a7816_d749_44e8_a55f_a4b4a6d475ea.eps"

export_fig error. Please ensure:
that the function you used (D:\Program Files\MATLAB\altmany-export_fig-d5538e9\export_fig.m) is from the expected location
and that you did not made a mistake in export_fig's expected input arguments
and that ghostscript is properly installed in D:\Program Files\MATLAB\gs9.50\bin\gswin64c.exe


Santanu Bir

Peter Li

Very good code. thank you very much, amazing quality .eps figures

Lukas Jung

Sorry, mistake web page, cancel my comment



Very nice, thanks. But, how can I export a figure with a specific size in inches and resolution? Setting the size of the figure before exporting and then exporting at a specified resolution doesn't work, because the function crops out the white areas and you end up with the wrong size.


Yoeri Boink

Maia Desamo

I love it

runze xu

Kuntan Ni

Beautiful function! It saves me a lot of time on saving figures, and has been my default choice.

tong lee


Meng Wang

Work perfectly for other formats.
But to eps format, there is an error: pdftops not found although there is indeed pdftops.exe in the install folder on Windows platform. However, when matlab throw that error and open the dialog to locate pdftops, it does not show that file.
Tried the methods here. But no help because I could not find a libfreetype.6.dylib. Not sure it's because they are on Linux platform. But anyway, the error still exist on Windows.

Used it to successfully append pdfs!

Ray Wu


Works perfectly to save figures with transparent background to PNG.

Sim Mah

Thanks a lot

Am I the only one who is having a lot of difficulties installing the pdftops required folder? I don't see why it's so confusing.

Xiaolu Zeng

Good stuff! Helps a lot for papers! Thank u.

I found a problem with labels having subscripts. Creating a figure with 'CMU Sans Serif'-Font and exporting in e.g. eps invokes space before the first subscript letter. I need this font for consistency with the rest of the document. Is there a way to fix the issue? Short example:


xlabel('Text x_1+x_2');
ylabel('Text y_1+y_2');

ax.FontName='CMU Sans Serif';

Qiang ZHU

Thanks for this perfect tool!

Simply perfect

Ufuk Tamer


Pau Packard

What I was looking for. Also had the issue with the white diagonal line in the colorbar, but only in pdf (using the transparent option) but not in tif.

Great tool!

Sajid Raza

very useful toolbox


I find export_fig to be very useful, and it does an excellent job in cropping the margin on the figure. I'm wondering if it is possible that the functionality of cropping is extracted as a more independent function, so that it can be very handy when we export the figure in formats not supported by export_fig, for example the emf format, which is a vector format, and is high compatible with MicroSoft Word. It will be much appreciated if the author or anyone else can do this.



the PDF problem from the post before only occur if there is non-vectorized data in the figure, like an image with imagesc. However, all the elements then seem to get saved rasterized. All text, the labels, gridlines, everything.


-pdf does not produce a vectorized pdf file for me but it always had before migrating to a new win 10 r2018b setup. Any tips? Newest ghostscript is installed of course.


Jasvir Bahl


Thanks for sharing, it is useful. emf support would be deeply appreciated.

Linwei Hu

Very very useful. Works perfectly in 2018a. Thank you very much for sharing it !

Damon Hyde

Amazing function!

This function solved the issue of non embedded fonts (Helvetica) in epstopdf figures for IEEE publications. Very helpful, thank you Yair Altman!

Doesn't export Latex fonts to pdf...

Yair Altman

SKG - export_fig does not [yet] support uifigures that were created using App Designer or the uifigure command, since it relies on Matlab's built-in print command, which is still not supported for such figures (at least as of R2018b).

Zhu Ruihen


Error using matlab.ui.Figure/horzcat
Conversion to matlab.ui.Figure from char is not possible.

Why am I getting this error?

Yasmin Samy

Thanks for this great code!!
Unfortunately, I having a minor problem. My figure also has a can i save both the graph and the uitable in the same figure? Currently, export_fig just ignores the uitable in the figure and saves only the graph.



Jun Meng

It's an amazing function! However, I can't export -esp format. Since I'm using MacOS, there is no Ghostscript and pdftops for Mac. Does anybody know know can i solve this problem?

Found error. Needed to update 2018b path is all.


Not sure why but this worked great for me until 2018b (2018a was ok) . Now with 2018b I get the following error:

Undefined function or variable 'using_hg2'.

Error in export_fig>parse_args (line 1157)
options.aa_factor = 1 + 2 * (~(using_hg2(fig) &&
isAA) | (options.renderer == 3));

Error in export_fig (line 280)
[fig, options] = parse_args(nargout, fig, varargin{:});

Any thoughts out there?


I should have known this function earlier. It's not straightforward to export high quality graphics from MATLAB figure. There are a lot to consider. But this function is a solution for many of those issues.

This worked very nicely until I had to export a figure with left and right y axes. In that case, the figure output is always smaller horizontally i.e. if you set a 10x10cm square figure, the output figure will not be square but shorter on the horizontal axis.

I found that the below issue was solved on R2018a

Hi, I have used this awesome function well, but recently, I got a problem.
I export my figure in EPS format.
In MATLAB figure window, there was no problem.
However, in exported EPS file, the position of marker was slightly right and upper shifted.
I think it might be the version problem.... but I don't have any insight.
Please help me...
I use 2017a, ghostscript 9.21, pdftops 3.04 on windows 10 64bit.
The last chage log in export fig is % 09/04/17: Added -linecaps option (idea by Baron Finer, issue #192)

Xiaoyu Yu



Thank you very much! That function is really useful!

Thank you very much for this very useful and wonderful tool! The only thing, which could be hopefully solved is some kind of distortion of exported images with the "-native" option. It seems, that the algorithm for this option produces several tiles of the original image and the tiles are shifted against another for some pixel to much in the wrong direction. This could probably be some kind of rounding problem or something like that....


I would like to point out the fact that export_fig does not look compatible with psfrag

It seems that the eps file output by export_fig is modified with respect to print or saveas, such that psfrag does not replace that tag.

Can anyone else comment on that?


I just struck a frustrating corner case. I was trying to export a new version of a figure, and got the error 'Could not create X.pdf - perhaps the folder does not exist, or you do not have write permissions'. It turned out that the previous version was open in acrobat reader, and Windows does not allow open files to be written to. Perhaps the error message could include a note 'if you are using Windows, please check that the file is not open in any other programs'?

Annu Singh

Yu Zou



Eyal Tal

Can this be updated to work with axes created in App Designer?


Josh Walker

Please ignore previous comment, just needed to run it in "function" form. Absolutely great. Thanks for your hard work!

Chris Hu

You are amazing and wonderful. Thank you!

Nico Spo

Jessie yu


addpath and use it! Thanks!

Really nice add-on and is simple to use. This is great if you are wanting to overlay computed surfaces or scatter plots of data from an image over the original image and still maintain the quality. Super helpful in making nice figures for publications!

When I use export_fig on an invisible figure ('visible','off') that contains uicontrols such as text boxes, push buttons, etc, mixed with graphs, the uicontrols do not get printed. If i do the same thing with the figure visible, everything gets printed. Is there a workaround/solution for this?


Very useful function, but it would be great if it also added support for EMF as it is after all the most MicrosoftOffice-friendly vector format!

I didn't manage to use this function within the App Designer environment.
I get the error "Undefined function 'export_fig' for input arguments of type 'matlab.ui.control.UIAxes'."
Is this type of object not defined for this function?
Is it furthermore planned to make this function work within App Designer?
Would be really helpful since the regular options (like print etc. ..) are also nopt (yet) available in App Designer.

Yu Xiao

Solve too many problems for me.

Hong Nguyen



Li Jianmin

Great job, allow high quality images. I allows to save (at high resolution and any format) exactly what is shown in MatLab.

Lara Román


I try to save a scatter plot with transparent color dots (FaceAlpha = 0.5). However, when I save the figure to pdf, the transparent effect disappear. I check online, and it said it is an issue has been fixed in export_fig. But I don't know how to get back the transparent effect of my scatter plot. Is there a method?


A similar question as SG's came up. The pixels are not square and the figure is stretched. Any solution?

Li Carl

Enhanced Metafile (EMF) is expected.


When I export a figure which is larger than the screen resolution with the "-native" option, the pixels aren't square anymore. Any idea how to solve this.


Bob DA

Fan Yang

lian xiang

Shane L

David P


Ferit Akgul

Ferit Akgul

Thanks a lot for contribution. However, I cannot seem to export an image file with the original image's quality even though output image resolution matches.

imshow('file.png') --> displays at %33 zoom since image is 4000x1000 pixels
export_fig -native --> outputs image at the same resolution (4000x1000) BUT image is heavily pixelated. Original image quality is not preserved.

How can I keep original image quality?

David P

This is fantastic and makes life so much easier!
I have had trouble when exporting as a figure as a pdf the title always gets cut off though

Zhiyuan Mao



I have finally taken the time (actually a few minutes) to get the hand with it and I am fully satisfied of it.

It might seems trivial for most of you, but may I recommend that a short note (for instance in the description) describing how to use it be added?
I.e., that the user should unzip the zip file, place it wherever he wants in its local disk, then he should add in his code
and then his figure can be save calling
(and see export_fig file for details about available output and input arguments).
Hope that helps!


ren ren

It's really useful! Thanks!


It is very useful. Thank you very much.

Thank you very much. It is very useful

ashkan ha

Easy to use. Excellent work!



Thanks so much. And I downloaded the last version. I find that Matlab r2016a no longer has /SO, /DO, /DA, /DD in the file, the fix_lines function would not work. Could you please resolve that or release a r2016a compatible version?

fan Wang

Thanks so much,
such an amazing tool.
I have a question please, how we can export figure in format (.fig) using this tool?


I use this code all of the time and love it. However, for my contourf maps with several axes or objects (like arrows), they take an inordinate amount of time to write to EPS. When I say a long time, I mean it might run for a day with no show of if it is even writing it, not even showing a filename in the folder it is being exported to. Do you have any suggestions on how I might speed this up? I use cropping to remove excess background space, CYMK for the journal I'm submitting to, and painters renderer. Any help would be appreciated, as this is beginning to drive me crazy. :(



Great tool.

Matt J

I don't think the issue of 1 pixel extra padding was truly fixed. I see a faint rim around exported images when placed on a black PowerPoint background slide

Yair Altman

@MichaelBevis - The Xpdf project was moved to on August 10, 2017. I updated the description text accordingly.

Hi, I was collating few matlab figures to one pdf using export_fig.Is it possible to add a matlab figure to a specific page of the existing pdf?
I know append can be used to add figure to existing pdf file but the problem is every time i mess up with the sequence (of figures ) I have to redo all the figures (in one pdf) again. So was wondering if a matlab figure can be added to a specific page of the existing pdf file.

This recommended link to xpdf software

> pdftops (install the Xpdf package):

no longer seems to work, Is there another source for the xpdf package?


How do I fix dotted lines blurring together for a 3-D plot? The 2-D plots look great, but in 3-D they blur together. I'm making a pdf so I believe the painters renderer is being used.

Nikki Brown

This worked a treat, thank you.


Daniel Wong

zhidong cao



Nicholas D.


Awesome, thanx a lot!

wu jun

Ander Cruz

Very nice and helpful function! However, it seems to have a problem mit date axes. I want to use your function to improve the quality of some time series plots with dates on the x-axis. When using your function, the created matlab figure has the first (oldest) date at the very right side of the axis and all subsequent dates shifted to the left. Then, it exports the described figure and after exporting it, the axis changes to the correct order with oldest to youngest.

It would be great if you could look into this issue.


This is the best solution I've found for creating high-quality PDFs. It's a lifesaver when I want to include graphics from MATLAB in a LaTeX document.

jon erickson


elvis ching

nice tool!
but it doesn't work after I use the tool 'freezecolors' , what can I do with it?

Hi Yair,

Excellent app, easy to use. You save my day!


Genius! Thanks

Jianke Li

Excellent work. Thumb up!


I had been searching for this one and I finally found it. Well done!


xinyu lei




I often get an error saying that I don't have enough "thread space". I am appending 14 charts. What Could I do to solve that?

good stuff!!!


Please, I would like to transfer png images into tiff, but I don´t know, where I put (load) my images for this transfer. Because I have this error:

Error using get
There is no Binarizace_okoli_ 1.png property on the Root class.
Error in export_fig (line 265)
fig = get(0, 'Binarizace_okoli_ 1.png');

Can you advice me?
Thank you for your answer.

l l

nice job man!

Great! Works perfectly and saves me a lot of time.


that's OK!


Good function! However, it doesn't print axis values properly specially when there is something like x10(-15). My code is given below:
t = 0:1/4:1; % test range
xa = sin(2*pi*2*t);
plot(t,xa,'.-'); grid on;title('tom');
export_fig test.pdf -native -transparent

ty long

john doe


Li Dong

Jiaqi Chen



I am plotting a grid of pixels in matlab and I have to overlay multiple grids on same figure using hold on (around 100). At the end figure become extremely heavy that if i zoom in a little portion of figure, it take computer to process an hour to zoom.
I was thinking to export figure on EPS format and then see the zoomed figure in EPS viewer. However, i am not able to see zoomed information of figure. Please let me know is it possible to preserve original figure information in EPS format so that when i zoom in EPS figure, I can see details just like in MATLAB?


Really useful function, thank you! However, there is a small bug that occurs when using the LineWidth option in conjunction with anti-aliasing:

figure(1), clf;
z = linspace(0,4*pi,250);
x = 2*cos(z) + rand(1,250);
y = 2*sin(z) + rand(1,250);
scatter3(x,y,z,'Marker', 'x', 'LineWidth', 4);
export_fig -a4

The saved figure will display points at default line width rather than the specified value.

Hello everyone, I used this function to export my figures to PDF. Then I used those pdf figures in my latex paper. When I uploaded the paper, I got "fonts not embedded" error. Is not this function supposed to embed the fonts already? What else should I do to not to get this error?

Joris Meurs

*.EMF would be great

Neil Arthur

In order to export to the desired size, using:
does not work on its own. You also need to change the LooseInset property with
Then use export_fig with no padding. Then the figure will print exactly to the desired size...Is this correct? Or am I missing something?

Leo Simon

Sorry, I downloaded the latest option and the issue I noted earlier has been fixed.

Leo Simon

It's a great addition, but there's one issue, which is that the padding option works only if options is a vector, which it isn't in my case. I hacked my code: on line 349 of export_fig, the third argument is hard-coded as a 1, if you change it to be options.bb_padding, then one can use the -p option generally. Hopefully this doesn't create other problems, but it seems to be working for me.


got to rate this full star. easy to use and handy

Simon Wyss




I have enjoyed using this package for many years. Of recent I've started to use the Parallel Computing Toolbox (PCT). Are there any plans on getting export_fig to work with the PCT? PCT in parfor loops use the -nodesktop and -nofigure options which export_fig doesn't seem well set up to handle.


one of the best toolbox. Thank you very much.

Very useful. The figure quality is very good

elvin feng

Good stuff here.

But I'm having an issue, when exporting to a tif and trying out the different options (-native, -q, etc) the output comes out the same resolution but the quality is diminished. 4x4 regions appear to be averaged into one which is quite the loss. Am I using the wrong options here to export or is this intended?


This function has made my life a great deal better for the last 7 years. Thanks a lot to the developer/maintainer!

BUT: after the sudden death of my previous PC and subsequent complete system reinstallation, pdf figures exported with export_fig now come in Courier font. Makes for fancy retro hipster style graphics but is unfortunately not an option for any kind of publications, and no solution found locally so far - I had to go back to Matlab's built in print function ):

Has anyone experienced similar behaviour? Is the problem on Matlab's or Ghostscript's side, or somewhere else?

Some clues:
- The Font tab in the pdf's Document Properties states: "any (Embedded Subset)" - somewhere in the exporting process the figure's font (Helvetica, I believe) goes missing.

- current system specs: Windows 7, Matlab 2016b, Ghostscript 9.19

- Browsing through older pdf files, I found that any pre-reinstall combinations of various Matlab and Ghostscript versions up to R2015b / 9.15 worked. There, the pdf specifies "Helvetica" as its embedded font (and thus it also displays Helvetica/Arial).


Hi, this export package is great, the plot quality is so much better than with the built-in Matlab functions.

What I am wondering is in the pdf export, that the grid, which constists of faint grey lines in the Matlab figure becomes a dashed white line in the pdf export. Since I am using dashed lines to separate visually certain regions in the plot the now white dashed lines are overlapping with my annotation lines.

In the png export output the gridlines are still in a faint grey color.

Where can I change that to get the same result for the pdf export as well?

Thanks and best,


Hello Yair,

Excellent contribution.. But i'm struggling with '-append' option because I want to put two gui figures in the same file and with your function I'm able to do that, but I loose some of the handles of my figures (e.g. uitables, string boxes..). Any ideas what could this be?
Best regards,

xueping li

Thank you for your contribution


Alexander H


Thank you for filling the gap. This is extremely handy!



Perfect. Thanks for your hard work. I had to download a newer version of export-fig to avoid eps2pdf error on 2015a.

Zhou Wei


Thank you very much for this. If I was choleric, you would have prevented me from beating up my computer because of the annoying and shitty handling of the print function. Unsuccessfully tried for over an hour to get rid of the outer padding of saved plots. With your script, it was about 8 minutes, including download time.

Kiran Sagar

I work on a computer where I don't have administrator rights. So, I can't install ghostscript. Is there any work around for that? (on Windows 7 - 64bit)

Awesome thanks


Ian Bennett

Very good program. However, I experience an issue when trying to export images with semi-transparent plotted points (using MarkerHandle.EdgecolorData and MarkerHandle.FacecolorData). The image that is exported does not show my points as semi-translucent, as they are in the plot. Instead, they show up as opaque.

@Miles, you can try out the following code to specify file name.

export_fig (sprintf('figure%d',mm));

I used it in a loop eg. for mm=1:5

cunjie zhang



Great function. Saved a lot of time.


I am having trouble specifying the filename when using this code looks something like this:

...[code to make my figure]...

temp_str = strjoin({'filepath\',filename},'');

When I do this, I still get a file saved in my directory which is named "export_fig_out.png". I was expecting that I would get a file with my "filename" that I specified.

Can anyone explain what I am doing wrong? I am slightly confused about the syntax for this function, I think.


Yue Chen

Great function. Thanks for sharing.

I have a question concerning crop! If I crop the image it won't be centered with respect to the plot box, because on the left side there is the YLabel. How should i modify the code so that the left space out of the box is equal to the space on the right (empty)?

many thanks!


renders EPS figure beautifully that was a mess when using the matlab defaults. thank you!

Daniel Cook

This is a life saver. I've used it to produce excellent figures for publications as well as presentations.


@ Yuri K: Thank you!

Hello unfortunately it does not work with geowshow and an image over a map.

[Singapore, R] = geotiffread(file);
s = size(Singapore);
matrix = rand(s(1),s(2));
geoshow(Singapore(:,:,1:3), R)
hold on
geoshow(matrix, R, 'DisplayType', 'texturemap','facealpha',.5);

And here the file of the image

if we do
export_fig test.png

it will not see the transparency as posted here:

Hello unfortunately it does not work with geowshow and an image over a map.

[Singapore, R] = geotiffread(file);
s = size(Singapore);
matrix = rand(s(1),s(2));
geoshow(Singapore(:,:,1:3), R)
hold on
geoshow(matrix, R, 'DisplayType', 'texturemap','facealpha',.5);

And here the file of the image

Yuri K

M FRZ: set(gcf,'color','w')


Hi , thanks for the code. how can I remove the gray border of the chart? export_fig gives me a graph with gray border (chart area color). I couldnt find the answer to this question.

Nat anunta



In order to make the code compatible with later MATLAB versions, you can change the code on line 14 in "using_hg2(fig)".

It should now be:
tf = ~verLessThan('matlab','8.4.0');

Earlier it was:
tf = ~graphicsversion(fig, 'handlegraphics');


I've been using this script for years. Haven't gotten around to rating this script until now. Thanks for this script; awesome work!


Great Work.



When I use this to convert a figure to a pdf/eps, I have "tiles" that are overlapping each other, causing for some filled circles to be cut in half, etc.

Is there any way to fix this?

Many thanks,



When I use export_fig to create .eps figures, both the x label and y label are not centered with respect to the axes; instead they are centered with respect to the cropped figures. I am using MATLAB2016a on a 64bit Ubuntu system. The following code can be used to demonstrate the problem described above:




axis([0 3*3.1415926 -1 1]);



export_fig test.eps -painters -r500 -q100 -cmyk -transparent;

Please help solve this problem. Many thanks!

Very helpful, thanks!

Really helpful!

Felipe Uribe

A great tool! Many thanks!


If we change the size of the figure showing in Matlab, the eps image size changes. Is there an option to resize to a specific eps file regardless of the figure?

A Lifesaver! I badly needed a transparent background in png output and it did it great for me.

Hello, I have a problem. I have 3 figures figure(1), figure(2) and figure(3). I try to put figure_hanfle=findall(0,'type','figure') and export_fig(figure_handle,'-pdf') and I have an error message "Handle must be that of a figure, axes or uipanel"...
Could you help me? I want to have a figure in each sheets of a pdf. Thank you

Diana Li

It works really good. :-)

I am getting the following error in matlab:

Pdftops not found. Please locate the program, or install xpdf-tools from

I too have installed xpdf as directed but am having no luck. Any suggestions?


Todd Karin

I believe I've found a bug. Please try the following code. You see that the peaks of the sine waves in the plot do not correspond with the peaks in the image.



x = linspace(0,30*pi,1000);
y = sin(x);

h(1) = axes('position',[.1 .15 .8 .3])
xlim([0 max(x)])

h(2) = axes('position',[.1 .45 .8 .3])
xlim([0 max(x)])


David Ho

Hi there, this tool is very capable. I have been looking for a similar tool to help me export a 3D plot with large amount of data that allows me to encode the axes/text differently from the data.

I came across epscombine and figure2eps but the tools are outdated. (see my question in the link below).

I wonder if you would consider adding those features to export_fig? Or does matlab natively already support them?


Awesome work, Yair! Thank you very much for creating, documenting and sharing this great function for us.



Awesome work, Yair! Thank you very much for creating, documenting and sharing this great function for us.


I had to change the line 131 in crop_borders from
B = repmat(bcol,(b-t)+1+padding*2,(r-l)+1+padding*2,1,n);

B = repmat(bcol,[(b-t)+1+padding*2,(r-l)+1+padding*2,1,n]);

Otherwise, it didn't work.

Juan Carlos


I have been using your code for quite sometime and really like it. Thanks.

Recently, I noticed that in exporting the figure to, say, a PNG image, the minor ticks were not produced. Any suggestions.



Thank you for the code!

Having one issue, though - the font of the labels on the colorbar becomes very tiny in the captured image. Any suggestions?


Hey, first thanks for this file!
I have a problem with exporting a figure to *.eps while using FontName 'Times' in Label and axis....

The exported *.eps image is always the same size and not depending on figure size.

My Matlab Version i use is R2015a.
Any suggestions?

Greetings and Thanks


Arne Zimmer


thanks for this great file!

But one thing: I use R2015b. I copied crop_borders.m, export_fig.m, print2array.m and using_hg2.m to my matlab folder and then I use this command:
export_fig test2.tiff -native

The file test2.tiff is in both directions 2 pixels larger than the original!!

Is there missing something?? What is my error?

Thanks in advance!!

Pedro Mateus

Loved all this project. Just one thing, when I try to export to eps or pdf I receive a message "export: Command not found." but everything is done...

Best, Pedro


Firstly: I love your script Yair, it's great and I use it alot! It really produces nice figures!

Secondly: I got a problem lately. I currently writing my dissertation thesis so I would like all my PDFs in CMYK colorspace, which worked fine for the first figure I made (I think at least).
But with another figure, I run into troubles as it seems not to save the PDF content in CMYK space. I am not sure how to check on it (only finding expensive tools for this) but when I open it in CMYK color space in Illustrator, colors change dramatically... I get the following warning when executing the script with these parameters (-pdf -cmyk -r300):

Warning: Multiple images & lines detected. In such cases, the lines might
appear with an invalid color due to an internal MATLAB bug (fixed in R2014b).
Possible workaround: add a '-depsc' or '-opengl' parameter to the export_fig command.
> In print2eps at 232
In print2array at 110
In print2eps at 394
In export_fig at 625

Yes, I am using R2012b because we have some old code that won't work properly in the newer versions of Matlab. Do you think that might be an issue? Or any other ideas? Possibilities?

Would appreciate help :)


Very precious tool, thanks a lot for that.

If it can help people: I had a problem using export_fig on figures created with functions of the mapping toolbox. The coast lines I was plotting together with my data were visible on the matlab figure but not on the file created by export_fig. To solve that I have used the uistack function to push my coast lines on top of the figure. For example:

line_coast=load('coast'); h_cl=plotm(,line_coast.long,'k-');
% insert here complex mapping toolbox plotting operations



I would like to thank the original author and the current maintainer for their outstanding work. For me, export_fig is a must!

People who write papers in electrical engineering or related fields might also take advantage of bibget. This is a tool I wrote to easily retrieve BibTeX entries from IEEE Xplore.

With export_fig and bibget, writing papers is much more fun! :-)


Youngmin Ha

Yair, can't thank you enough to show my appreciation for this function. I'd been using it for manuscript figures for over two years now.


On El Capitan I cannot use export_fig to export into eps. Precisely, that's the error I get:

Pdftops not found. Please locate the program, or install xpdf-tools from

I also tried to install xpdf as indicated, but still the same problem. Could anyone please help me?

On El Capitan I cannot use export_fig to export into eps. Precisely, that's the error I get:

Pdftops not found. Please locate the program, or install xpdf-tools from

I also tried to install xpdf as indicated, but still the same problem. Could anyone please help me?

Great script! Do you know how I can export a panel within a tabular. The problem is that the panel original dimensions are not kept but the dimensions of the tabular are taken.

Not sure if this is a bug or intended ? Is a workaround possible ?


This submission no longer (2014b onward) improves line styles in exported eps figures... As this file is still getting updates may be author should check this feature.

I forgot to add the correct search path, sorry! With the current version I do not get the warning any more.

Sorry for posting twice the last time ... is there any way to delete a comment?


Great tool! thanks for the contribution. I'm just having a bit problem. I'm loading and modifying an image of 360x360 pixels. When I export it with export_fig I get an image of 362x362. Could you give me a hint why? I'm using Matlab 2014b in Windows 8. Thanks!

Recently I get the following warning message in R2015b when using export_fig with boxplot and plot:
Warning: graphicsversion will be removed in a future release.
In using_hg2 (line 15)
In export_fig>parse_args (line 797)
In export_fig (line 216)

Thanks for the great file, I am using it since a few months and I am thrilled :).

Recently I get the following warning message in R2015 when using export_fig with boxplot and plot:
Warning: graphicsversion will be removed in a future release.
In using_hg2 (line 15)
In export_fig>parse_args (line 797)
In export_fig (line 216)

Thanks for the great file, I am using it since a few months and I am thrilled :).


It works pretty fine with R2015b.

Dan K

Note that saving to the clipboard was broken in R2015b. The fix is described in (apply at line 733):

Carlos Meza

Excellent contribution. I have problems with (surfc,meshc) not generated vectors. When I am using surf if generated. Any solution?. Thank you very much for your collaboration


Plotting works fine except of plots generated by using bar() or histogram().
There I can't get any transparent pdf files with vector graphics.
My command used was:
export_fig( 'histo.pdf','-pdf', '-transparent',figure(1))


Plotting works fine except of plots generated by using bar() or histogram().
There I can't get any transparent pdf files with vector graphics.
My command used was:
export_fig( 'histo.pdf','-pdf', '-transparent',figure(1))


Excellent when I want to get a transparent figure. Thank you very much!


Andy Hueni

PDF export works for me on Mac OS X El Capitan with R2015b after installing Ghostscript-9.16.pkg from
Had to move to this package as the Matlab fillPage and print functions I used till now messed it up after the Capitan upgrade, can't say if it applies to Yosemite as well.


I've been using this function since forever to produce article-level figures with tight control of the dimensions

Yair Altman

@MSch - export_fig works well on R2015b. The removal of the builtin Matlab ghostscript does not affect export_fig, since export_fig does not depend on it. You can install ghostscript executable directly from and then export_fig will use it.

I remind everyone that I will not respond to feature requests or bug reports in this comments section - if you have something to request or to report then use Github's issues page to report and track your issue:


does not run with Matlab 2015b due to this: "MATLAB no longer ships with the Ghostscript® library. Remove all instances of code that use ghostscript.m." (see ReleaseNotes -> graphics -> Functionality being removed or changed)

I'll stick with 2015a till there's a workaroud, because I love this tool, especially the append_pdfs function :) Thanks!


I have been using export_fig for a long time. After switching to R2015b, it threw a warning about using an obsolete function (graphicsversion, I believe) so I got the latest version. This produces an invalid eps file,so the eps2pdf crashes. Preview also cannot open the eps file. The error report from ghostscript is
Error using eps2pdf (line 107)
Error: /undefined in bdef
Operand stack:
dom --nostringval--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval--
--nostringval-- 2 %stopped_push --nostringval--
--nostringval-- --nostringval-- false 1 %stopped_push
1951 1 3 %oparray_pop 1950 1 3 %oparray_pop 1934
1 3 %oparray_pop 1820 1 3 %oparray_pop
--nostringval-- %errorexec_pop .runexec2 --nostringval--
--nostringval-- --nostringval-- 2 %stopped_push
Dictionary stack:
--dict:1194/1684(ro)(G)-- --dict:0/20(G)-- --dict:78/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 64
GPL Ghostscript 9.16: Unrecoverable error, exit code 1

Please help!


Wonderful code

Great tool, really improves the look of my graphs. Only thing so far is that cropping is either on or off, with no option to crop only top/bottom or left/right. I need this to have proper scaling of the plotbox area in Latex files. I had to fix it by just disabling left/right cropping in the crop_borders.m file disabling it for good. Would be great to have specific command for left/right/top/bottom cropping on or off. That's just a minor thing though.

Ben Webber

Great tool.

However, it seems that when text objects are positioned using normalized units, these positions are not properly retained when exporting the figure. I regularly use normalized units as I find these more intuitive. I'm using Matlab 2015b on MacOS 10.9 (the problem also occurs on Matlab 2012b).


I have been trying to solve the transparency issue for a long time. Now it's finally solved! Thank you!


Hello Yair,
Has print2eps been tested with R2015b? It seems that the font mapping doesn't work.

I have a figure with Times font throughout (roman and bold). I made an eps using print2eps, but when I imported this in MS Word and tried to create a PDF file, I get a message like:
%%[ Error: Times-Roman-Bold not found. Font cannot be embedded. ]%%
%%[ Error: invalidfont; OffendingCommand: findfont ]%%


%%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
%%[ Warning: PostScript error. No PDF file produced. ] %%


By the way the 1 star rating was an accident. I rate this file 6/5.

I have also noticed greek letters distorted when using export_fig. I used to export as -png with compression -m3.
Exporting to pdf file removes the greek letters problem, and increases the quality of the plot.


I use this all the time to create plots, and it has been great! Recently I've noticed it does not create Greek letters correctly in the title. There is another post on Github noting the same problem for Matlab 2015a. I'm using Matlab 2014b on Windows 7. Does anyone know why this is happening or how to fix it?

Thanks for the help!

xinlu wang

Keegan Moore

Jitin Beri



This is working great for me with exception of using it with the function Magnify on Figure.

For some reason, when Export_Fig runs, the x-axis of some of the magnified figures changes to become illegible. Its almost like some additional decimal places are added to the x-axis and they all overlap each other. As soon as Export_Fig is done, the axis goes back to normal.

Any help on this would be appreciated.

This is my favorite tool to export graphics. However i found that i am not able to export markers that have a certain amount of alpha parameter(yes i found a way to do it and maybe you can find it if you dig on internet). When i export to eps the effect of shade in the background of the marker disappear. The way that i can set transparency in markers is the following:

sMarkers=h1.MarkerHandle; %h1 is line handle
sMarkers.FaceColorData = uint8(255*[0;0;0;0.5]); %fourth element allows setting alpha
sMarkers.EdgeColorData = uint8(255*[0;0;0;0]);


Hi there,

This is a great code but I cannot seem to understand that when I try to use export_fig with larger font sizes, a grey box appears over my axis labels when I try to export the figure in a higher resolution. This is slowly driving me insane and I cannot seem to find anything on it. Perhaps it is my graphics card? Or just me? I use something like this for instance:

export_fig 'filename.png' -png -opengl -r150;

It's an amazing tool.

Thanks for maintaining to support 2014 and 2015 MATLAB versions.

I am wondering why the font is extremely small under linux? I have tried both gentoo and ubuntu, the problem persists. matlab version also have been tested but all ends up with very small fonts.




Hi.. Actually i used this code last year to save fig as pdf and append the same, and it worked great..
but now when I try to use 'append', unwanted patches appear on the appended pdf file. I am using MATLAB 2014b. Will you be able to help me out.??
otherwise, the code works great.!! superb job!!


Vital !!
Thank you very much !

Solves all my issues with Matlab - LaTeX compatibility.


Alan Cole

FYI. For my comment on May 13th I corrected the issue by temporarily turning of Windows 7 UAC. When set to none it worked correctly.



R2015a, Mac Pro, Mavericks. Exporting to PNG. Works great, fixed my sizing and clipping problems.

Alan Cole

With the new version I receive the following error:

Warning: Path to ghostscript installation could not be saved. Enter it manually in C:\Program

The \.ignore\ghostscript.txt does not currently exist.

Peng Xu

Great tool

I have a problem with the exported .png file. The exponential notation on the top of the left Y axis does not show in the png exported image. Has anyone experienced this?
For instance I have a plot with value 0 to 5 "x10^-12". The exponential shows at the top of the axis but none of the formats I have tried (eps, pdf, jpg, png) show it.

Otherwise, nice work!


I have used this tool in matlab 2013a and it works perfectly. In matlab 2015a, the exact code gives a issue with exporting imagesc figures with colorbars. It always displays a white diagonal stripe from botton left to bottom left to top right. This occurs no matter which colormap is used. Has anyone tried it on 2015a so far?

ps : excellent work

It works excellent for me.

Nicholas D.

Menno Poot

A great utility to export my figures to high quality .eps files.


When exporting Matlab2015a ".fig" file to ".pdf", the edges are cut off, especially the right side.

Sergei P.


I'm having trouble with matlab 2015a
Below is my error message
Thanks for your help

Error using eps2pdf (line 107)
Error: /undefined in bdef
Operand stack:
dom --nostringval--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval--
--nostringval-- false 1 %stopped_push 1983 1 3 %oparray_pop 1982 1 3 %oparray_pop 1966 1 3 %oparray_pop 1852 1
3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push
Dictionary stack:
--dict:1201/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Current file position is 64
GPL Ghostscript 9.15: Unrecoverable error, exit code 1

Error in export_fig (line 433)
eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality);

Lei Ding


Converting a figure with non-standard screen size to pdf on Unix fails

I am trying to convert figures with non-default screen sizes into pdfs:

% open matlab figure file

% change figure size to non-default size
set(h,'units','normalized','outerposition',[0.1 0.1 0.5 0.5]);

% convert fig file to pdf
export_fig('out.pdf','-pdf', h, '-nocrop','-transparent','-painters', '-append');

This works nicely on Windows, but on Unix the figures in the pdf all have the same default size. Any ideas?

great, but i have a problem.
ich will append a few pdfs.
this pdfs have variable filesnames und paths. I got follow error:

Error: /undefinedfilename in (Auswertung_24-Mar-2015\\-2.2-\\2.2_Extraktionsgte.pdf)
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1191/1684(ro)(G)-- --dict:1/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.15: Unrecoverable error, exit code 1

thanks for help


Serves the purpose very well. Thanks!


I found the answer to my earlier question:
export_fig('exportfig_painters.png', '-png', '-painters', '-r300');

It works fine.


I had used this program successfully in the past for printing figures made in matlab. But now I am having a problem. I am trying to print a high resolution map made using geoshow in matlab mapping toolbox. But when I execute the command say export_fig finename.png -r600, the file is saved but only the axis labels are printed, and not the whole figure. I can still print several other figures successfully, so the problem must be related to the mapping toolbox. Could you please help?
Thank you very much.


Helped a lot, thanks!

Yair Altman

@Aniket - yes, export_fig does indeed accepts a handle to a figure/axes/uipanel

To all the others - you need to report the issue in the GitHub, otherwise they will not be tracked or fixed:

Before submitting a new issue, please verify that it was not previously reported.



I have the same issue as James Rankin in Matlab 2014b:

Error using eps2pdf (line 107)
Error: /rangecheck in definefont
Operand stack:
CMMI10 --dict:14/15(L)-- Font
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval--
--nostringval-- 2 %stopped_push --nostringval--
--nostringval-- --nostringval-- false 1 %stopped_push
1951 1 3 %oparray_pop 1950 1 3 %oparray_pop
--nostringval-- 1934 1 3 %oparray_pop 1820 1 3
%oparray_pop --nostringval-- %errorexec_pop .runexec2
--nostringval-- --nostringval-- --nostringval-- 2
%stopped_push --nostringval-- 1901 2 3 %oparray_pop
Dictionary stack:
--dict:1188/1684(ro)(G)-- --dict:0/20(G)-- --dict:121/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 90501
GPL Ghostscript 9.15: Unrecoverable error, exit code 1

Error in export_fig (line 442)
eps2pdf(tmp_nam, pdf_nam, 1, options.append,
options.colourspace==2, options.quality);

Error in fit_ramsey (line 210)
export_fig(['fit_' filename], '-pdf');

Unfortunately, his fix is not working for me... It was working well with 2012b, I don't understand, as I am working with standard fonts...
Anyway, great soft, very usefull for scientific works !

Brilliant tool! Image quality in pdfs is really good.

I was wondering if in case of multiple figures, could we use figure handles when using export_fig?

Great code! It worked without any fiddling in R2014b and created high-quality PDFs that I can use for professional presentations, posters, and publications. Thanks a lot for making and maintaining this code.

I have the legend at the Southoutside with horizontal orientation. When the box of the legend is set to 'off', a little bit bottom part of the legend is also cropped when exporting figure to eps and pdf (no problem with png). There is a no problem with box outline. The problem persists in MATLAB R2014b.

Does anyone else have similar issue?


Kai Shi

I added a rectangle box in the figure and change the transparency of the box to 0.3. However, when I export the figure into latex. The transparency of the box is still 100%. With and without the -transparent option shows the same results. The code of generating the box is shown below:


Thank you for this library, it is really usefull! Unfortunately, I am having serious issues with export_fig, specifically with the fileparts(tempname) portion of the code that specifies a temporary folder that the program uses to create/delete temp images. It is trying to use the system32 folder for one of our users and it is giving him access violation errors and crashing. I would like to be able to specify my own user specified temporary path on his computer that he does have read/write access to. This is not a capability of the tool out of the box but could be a simple optional addition that would save us a lot of grief. For now, I will have to do this myself on my export_fig copy. Thanks!




I was receiving the following error after upgrading to Matlab 2014b (in Ubuntu 14.04):
Error using eps2pdf (line 107)
Error: /rangecheck in /findfont


Error in export_fig (line 442)
eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality);

I fixed this by commenting the following lines in eps2pdf

fp = font_path();
if ~isempty(fp)
options = [options ' -sFONTPATH="' fp '"'];

Yiqun Yang

To be more specific, here is the example code.

xlabel('Frequency (Hz)')
ylabel('attenuation (Neper/m)')
export_fig test -pdf -transparent

Yiqun Yang


First thanks a lot for providing such a wonderful toolbox!

However, here I've found a bug when I switch to Matlab 2014b. In Matlab R2014b, when I was using the toolbox to generate pdf figure as:

export_fig ConvEstimateatten -pdf -transparent

The margin of the figure is not cropped as desiered. Could you have a look at it?



I've got another issue: How can I save the file in a different subfolder. I created a subfolder Fig and then, tried:

export_fig ../Fig/fig.pdf;

but that gave

Error using eps2pdf (line 107)
GPL Ghostscript 9.10: **** Could not open the file ../Fig/fig.pdf .
**** Unable to open the initial device, quitting.

Error in export_fig (line 442)
eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality);

What am I doing wrong?


I'm still a bit puzzled how to display tex symbols. For instance, one of my titles is
and is properly displayed in the figure, but not the printed pdf (there, I get a colon to the power of w). I'm using the latest version of texshop 3.49.


To clarify, I'm trying to export a plot with a legend from a GUI axis using export_fig(handles.myaxis, filename). The legend does not show. If I plot with a legend from the command window and save the figure with export_fig the legend shows correctly.


Excellent function!

However, using 2014b, the legends disappear from my plots. This does not happen with 2014a. Is there a workaround or missing argument for 2014b?

Yair Altman

@Ian Zammit - the utility's changelog is listed at the bottom of this webpage.

@Linh, Ruben, Iain - please create corresponding issues in Github (check if the issue already exists there, before posting a new one). I have just received ownership of export_fig's maintenance and it could take me some time to dive into things and be able to fix them, so please be patient.

@Ragheb - try to update your ghostscript executable to the latest version. Perhaps your existing executable is incompatible with your platform and causes this crash.

Linh Nguyen

Excellent tool! Thank you a lot. It works for most cases for me, except when I need to plot and export a big field (200x300, pcolor). Could anyone try and tell me why I cant get a resolved image please? Results I got is also in the folder:

Ruben Luis

Brilliant contribution!
However, it seems that something significant has changed when using R2014b. It does not seem to be possible to reduce the thickness of axis borders. Can you advise a workaround?

Ben Puttnam


Very very helpful, and easy to use.



export_fig works perfectly for small figures when I use this command: "export_fig test.pdf". However, using the same command, Matlab crashes for large figures and it gives me this error:
Exception type: Bus Error (0xa) at pc=7fff887be082

Also, I tried export_fig test.eps, but it does not even work?

Many thanks



export_fig works perfectly for small figures when I use this command: "export_fig test.pdf". However, using the same command, Matlab crashes for large figures and it gives me this error:
Exception type: Bus Error (0xa) at pc=7fff887be082

Also, I tried export_fig test.eps, but it does not even work?

Many thanks

from my experience works perfectly! Is there a list of changes for the version uploaded 08/12/14? The one within export_fig and some other .m files seems not to be updated


Hi Oliver,

Thanks for an excellent function!

I am using a current version of export_fig (today), OS X 10.10.1, ghostscript 9.15, and Matlab 2014b. All works fine when I set up a figure and run:


However, if I then run:

>> set(groot,'Units','normalized')

I now get:

>> export_fig(fname,'-pdf',fh);
Error using eps2pdf (line 107)
Error: /configurationerror in --setpagedevice--
Additional information: [/PageSize [0 0]]
Operand stack:
--nostringval-- (%%BoundingBox: 0 0 0 0) --dict:1/2(ro)(G)-- --nostringval--
--nostringval-- (%%BoundingBox: 0 0 0 0) 1 0 0 false --dict:1/1(L)--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2
%stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
1951 1 3 %oparray_pop 1950 1 3 %oparray_pop --nostringval-- 1934 1 3
%oparray_pop 1820 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2
--nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
%ztokenexec_continue (scanner state) --nostringval-- --nostringval-- --nostringval--
--nostringval-- --nostringval-- --nostringval-- 1913 10 3 %oparray_pop
--nostringval-- --nostringval-- --dict:1/10(L)-- --nostringval-- 16 %dict_continue
Dictionary stack:
--dict:1189/1684(ro)(G)-- --dict:0/20(G)-- --dict:81/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 266
GPL Ghostscript 9.15: Unrecoverable error, exit code 1

Error in export_fig (line 442)
eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality);

The output is now a blank PDF. Clearly, I can work around this by not invoking:

>> set(groot,'Units','normalized')

That said, it would be nice to have export_fig resilient to this setting.




Hi Oliver. Sorry. I have not heard about GitHub before. Otherwise I would not bother you asking here.

I created an issue.

Thank you.

David Nolan

Great function and badly needed for HQ figures for publishing. You have my thanks Oliver.


Sorry, never heard of GitHub. Now I see it at over there above the Download Zip button. Not familiar with it.

Philipp: There is absolutely no chance without an issue raised on GitHub.


Is there any chance that there will be a fix for the totally "jagged" lines all along a graph when exporting to either of those formats: png, eps, pdf, ... ??

The strange thing is: if I use saveas PNG, the Problem is not occuring. With export_fig (PNG) is occurs. So I suppose export_fig first creates a vector format and afterwards a PNG of it, which can explain that.

Anyway: I need MATLAB 2014b for some other features and ask myself if there is any chance to get this bug fixed?

Valjean, R2D2: For the 100th time (and beginning to wonder what is wrong with people), I do not address issues placed in the comments. If you want me to look at your problem, raise a GitHub issue and we can talk.


Update: export_fig works fine on the screen-sized figures when I remove the
'-transparent' argument.