Code covered by the BSD License  

Highlights from
Exportfig

4.25

4.2 | 38 ratings Rate this file 113 Downloads (last 30 days) File Size: 11.3 KB File ID: #727

Exportfig

by

 

13 Sep 2001 (Updated )

Functions for exporting figures.

| Watch this File

File Information
Description

A collection of 4 functions to make it easier to export figures for publication. See also http://www.mathworks.com/company/newsletters/digest/december00/export.html

Acknowledgements

This file inspired Ba Fig Ex Pro (V. 2.7), 2 D Mohr's Circle, Figuremaker Publication Quality Figures With Matlab, and Pi Vlab Time Resolved Particle Image Velocimetry (Piv) Tool.

MATLAB release MATLAB 6.0 (R12)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (49)
03 Nov 2014 Gideon simpson

There seems to be issues with this in 2014B, at least on OS X 10.9.

17 Sep 2013 Lennart

Nice tool but export to pdf gives errors in my case. Adobe reader says it is damaged, although the standard (evince) can open them.

(R2012a, Ubuntu 12.04 32bit)

31 May 2013 Todd Karin

I modified this function to include rgb color scaling and output to pdf. Please see:

http://www.mathworks.com/matlabcentral/fileexchange/42012-figuremaker-publication-quality-figures-with-matlab

09 Mar 2013 Todd Karin

Bug: exportfig does not export colors of a 'jet' colormap correctly.

26 Apr 2012 Shinobue111  
01 Mar 2012 Dmytro Lituiev

I had a problem with logarithmic scales, namely the tick labels were changed:
base '10' is removed, i.e. 10^-1 -> -1 etc.

23 Dec 2011 Xin  
21 Jul 2011 Eli

Great software.

How do you control the size of the output PDF or EPS? I want to reduce the size.

In addition, the -painters option does not work for me, in pdf/eps files. I tried it on various linux and win systems.

12 May 2011 Geoffrey

Nice utility.

Why have you chosen to ignore the rgb color scheme? Print handles them as a default and I would expect this to as well (or at least an option).

The easiest fix is to take line 282 and replace
args = {args{:}, ['-d' format],'-cmyk'};

with

args = {args{:}, ['-d' format]};

15 Mar 2011 Brad Z

Found the axis problem!
exportfig(...,'LockAxes',0,...)
Made the 1e1, 1e10, etc. return to my x-axis (as opposed to before, where it was 0, 1, etc.).

04 Mar 2011 Troy

Line 967 error if ylabs iscell. Same error as Yuaval. I set my ylabels to a cell array of strings. A quick fix for me, but I figured I would mention it. Thanks!

26 Nov 2010 Image Analyst

Just to avoid any confusion, people should know that there is a similarly named routine by a different author (Oliver Woodford). It's called export_fig and can be found at http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig

12 Oct 2010 Eric Durant

Great tool, but calling colorbar after contourf causes exportfig to fail with "invalid handle" in R2010a. Using latest version from Oct 2009.

26 Sep 2010 Claire

Brilliant! I have spent days trying to get my figures to export and this file did it instantly!
Thanks so much!!

10 Aug 2010 Jens Färber

Great pice of software!
There is a minor bug in handling Axes Labels. The Following codereproduces the error:

x=[1:10];
y=[6:15]*1e-5;
plot(x,y)
set(gcf, 'Name','The exponent of y-Axis is missing in eps');
exportfig(gcf,'dummy.eps');

Thanks for fixes!
Jens

P.S. Working with Win XP, Matlab R2009a

20 Jul 2010 Patrick Mineault

Works great. Two tweaks you might want to consider are:

- Hi-resolution preview (with antialiasing). With the regular preview you often can't tell whether a line is disproportionately thin or thick. You can get 4x resolution previews which solve this issue by replacing these lines in previewfig:

line 21: args = {'resolution',96*4,'format','png'};
line 36: image(imresize(X,.25));
line 39: axesPos = [0 0 width/4 height/4];

- Close Preview window automatically. It often happens that when calling exportfig after previewfig you forget to close the preview window and it exports the low-resolution preview window rather than the actual content. In exportfig, this can be fixed by adding at line 150:

if strcmp(get(H,'name'),'Preview')
warning('exportfig:PreviewOpen','Preview window was open; closing before exporting');
close('Preview');
H = gcf;
end

16 May 2010 Yuval Aviel

minor bug: when xlabels is a cell array, str2num(xlabs(1,:)), line 1006, triggers an exception.
Here is a suggested fix:
So line 1007:
((str2num(xlabs(1,:)) ~= xticks(1)) | ...
should be:
(iscell(xlabs) || (str2num(xlabs(1,:)) ~= xticks(1)) | ...

should probably be the same for other axes (y and z).

27 Jan 2009 Jonas  
22 Jan 2009 Eric

Why is all this functionality not yet added to matlab's hgexport.m file? The tight bounding box calculation which includes ALL text labels vs. just the axes is clearly an improvement. I am using 7.7.0.471 (R2008b)

19 Dec 2008 Vincent Huang

Doug, could you elaborate on this work-around a bit? Sample code involving applytofig is highly appreciated.

14 Jul 2008 Doug Saucedo

I found a work around for my previously posted issue. I'm using the applytofig function to adjust the figures attributes then using print(fig,...) to write the image file. This is an excellent package for use with TeX/LaTeX/PDFLaTeX,etc.

27 Jun 2008 Doug Saucedo

I've been using exportfig for several years and until recently had not had issues with it. Overall this is a great function set.

I'm hoping someone will have some feedback regarding how to get exportfig to not "corrupt" subplot figures or contour plots with a colorbar. Exportfig attaches extra white space in both cases and deforms the plot in the subplot case. Thanks

19 Mar 2008 sarah goldberg

overall very helpful - solved a problem i was having with text labels on top of mesh plots. BUT - uses negative values for bounding box when exporting to EPS format, which is not ok for dvi->pdf (assuming you're working with latex).

07 Mar 2008 sharee_adil sharee  
11 Jan 2008 Chris Barrington-Leigh

This would be much more useful if it worked in nodisplay mode (matlab -nodisplay -nojvm) for batch processing, which is vastly faster than showing everything on screen.

Exportfig fails as follows under nodisplay mode:

??? Error using ==> exportfig at 744
Error using ==> graphics/private/setset at 307
Error using ==> graphics/private/setset at 277
Error using ==> set
Width and height must be > 0.

05 Jan 2008 Christopher Barrington-Leigh

Very nice tool. But what else has come along in the intervening years? Matlab should provide something more like this, without bugs.
My biggest bug with it so far is that when my hlabel includes tex formatting, the bounding box ignores (?) it and cuts it off. So I'd have to edit each figure by hand (illustrator? scribus?) to enlarge the bounding box.
Is someone maintaining this?
Well, I've nothing better for now, so am using this for my dissertation.

23 Aug 2007 Prasad Gabbur

I wanted flexibility regarding font size for a plot's legend, which does not seem to be handled well by Matlab. exportfig was helpful to me in dealing with this problem by playing with the 'FomtMode' and 'Fontsize' properties. Thanks to the authors!

07 Feb 2007 Chris Churchill

Another annoying problem I have found with this script which is probably related to Matlab in general: when creating greek letters or symbols in a text box on a figure using tex encoding, Matlab always defaults to display these characters in "Symbol" font, even if you explicitly set it as "Helvetica".
If you would like your figures to look correct in Adobe Illustrator, it is necessary to find a workaround for this, since it does not always display the font correctly.
Even if Greek characters are part of a font, you can not use them directly.

01 Feb 2007 Chris Churchill

Pretty good for actually getting useful plots out of Matlab. Formatting tends to be a little bit messy, if you need to post-process in Illustrator or Inkscape.

09 Jan 2007 chau nguyen

exportfig.m

16 Oct 2006 Roger Svensson  
03 Apr 2006 Rentian Xiong

Worked great for me. Saved lots of time to incorporate Matlab figures with Latex. Thanks!

15 Mar 2006 Anonymous User

In version 2002-10-18, line 451:

set(H,'Color','w');

isn't necessary at all. If another figure color is used, this command will undo the figure color set before. Besides, the figure property 'InvertHardcopy' is meant to handle figure color and turn it into white if necessary.

12 Jan 2006 Andreas Groth

I've tried the command
previewfig(gcf,'bounds','tight');
with the first example in "Exporting Figures for Publication: Part 2" and nothing happens. Only the colored lines are converted to black ones, but the bounds are the same. If I export it to eps, the labels are not correctly shown and are still clipped.
I've Matlab R13, perhaps it works only with R12?

22 Sep 2005 Madhusudhanan Balasubramanian

Use exportfig(...., 'lockAxes', 0) to freeze the axes (and prevent stripping of the exponent of the y-axis)

18 Jul 2005 Gerard Ridgway

Ah, sorry Randall, I see what you mean.

plot(1e9)
applytofig(gcf)

strips the multiplier from the axis numbering itself, and not the axis label as I had thought.

18 Jul 2005 Gerard Ridgway

I think this is a really useful tool, which deserves to be included in future MATLAB releases. If Ben Hinkle doesn't have time to maintain it any more, surely someone could volunteer (just not me...)

Randall Schuh -- can you reproduce your bug? I find things like:

lab = ['\omega' sprintf('\n') '(10^{3} Hz)'];
xlabel(lab)

work fine for me.

I agree with Magnus Nilsson's bug report, but know of no better tool. You could try LaPrint

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4638&objectType=file

But this is takes quite a different approach, is much more complex, only usable with LaTeX, and doesn't seem to offer the very useful exportfig option of changing line styles for mono export.

01 Jun 2005 Randall Schuh

I have used exportfig for a while, but it is slow, the code is pretty complicated and it is stripping the units off of my axes (e.g. x10^-3 is removed from the axis). It seems that these files are not being updated and I'm not sure I want to try to figure out enough of what it is doing to fix it.

25 Oct 2004 jiansheng chen  
21 Sep 2004 Magnus Nilsson

The idea is great, but on my first try it could not handle hist plots. Is there some similar function out there that works better? It would help a lot.

23 Aug 2004 Shi Jin

Bug: Cannot get the specified width or height correctly if the plot is maximized by the user.
I wonder if there is a version number to this package so that I can make sure I am using the latest one. Or is this package ever bug-fixed at all? Thanks.

21 Aug 2004 Mark Histed

Bug: if any tick labels are cellstrs (as opposed the char arrays), EXPORTFIG fails.

24 May 2004 john kerry  
31 Mar 2004 Fred V.

solves a common bug in matlab: translation/rotation of added elements (legend, lines, arrows, text) when converting from *.fig to another picture format.

19 Feb 2004 Stephan Zeipel

Doesn't work if Axis has no ticks

02 Jul 2003 Jason R.

An excellent tool -- I've found it very helpful putting together my PhD thesis.

21 Jan 2003 Vio B.

Very helpful for exporting "publication quality" eps figs quickly.
It still needs to be fixed to handle "single column" figures (width <=3.25in) correctly.

05 Oct 2001 Jeff Hebert

Good integration with MATLAB - ability to set default options is nice. Still screws up axis labels occaisionally but overall a must have.

14 Sep 2001 Denis Gilbert

I have used the exportfig utility several times over the last year and highly recommend it to anyone using matlab graphics in their presentations or publications.

Updates
15 Oct 2002

some bug fixes

14 Oct 2009

BSD update

28 Oct 2009

remove contact email address

Contact us