File Exchange

image thumbnail

Exportfig

version 1.2.0.1 (11.3 KB) by

Functions for exporting figures.

4.21951
43 Ratings

47 Downloads

Updated

View License

A collection of 4 functions to make it easier to export figures for publication.

Comments and Ratings (58)

elvis ching

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

Zhifan Z

Yair M

Yair M (view profile)

Akash Jain

I am using this in my code(MATLAB R2016a):
% Export figure to tif file
exportfig(gcf,strrep(fname,'.def1.txt','.tif'),'Format','tiff',...
'Color','rgb','Resolution',300)

I am getting following error:
Error using exportfig (line 743)
Error using str2num (line 32)
Requires string or character array input.

Error in MatLam_Tut3 (line 28)
exportfig(gcf,strrep(fname,'.def1.txt','.tif'),'Format','tiff',...

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I tried the following:

The previous comment solved the problem

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).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
It did not worked for me and I am getting same problem.

also in exportfig script
line 743 : error(deblank(lasterr)); Matlab suggests not use lasterr

mike

mike (view profile)

The previous comment solved the problem

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).

mike

mike (view profile)

in my code I use:exportfig(gcf,'Al_SC_100.tif','Format','tiff',...
'Color','rgb','Resolution',300)

I am getting this error:

Error using exportfig (line 743)
Error using str2num (line 32)
Requires string or character array input.

Error in calc_fcc (line 30)
exportfig(gcf,'Al_SC_100.tif','Format','tiff',...

ping

ping (view profile)

function generates error with option 'Format' in r2014b.

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

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)

Todd Karin

Todd Karin (view profile)

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

Todd Karin

Todd Karin (view profile)

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

ww

ww (view profile)

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

Xin

Xin (view profile)

Eli

Eli (view profile)

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.

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]};

Brad Z

Brad Z (view profile)

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.).

Troy

Troy (view profile)

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!

Image Analyst

Image Analyst (view profile)

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

Eric Durant

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

Claire

Claire (view profile)

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

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

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

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).

Jonas

Jonas (view profile)

Eric

Eric (view profile)

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)

Vincent Huang

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

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.

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

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).

sharee_adil sharee

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.

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.

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!

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.

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.

chau nguyen

exportfig.m

Roger Svensson

Rentian Xiong

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

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.

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?

Madhusudhanan Balasubramanian

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

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.

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.

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.

jiansheng chen

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.

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.

Mark Histed

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

john kerry

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.

Stephan Zeipel

Doesn't work if Axis has no ticks

Jason R.

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

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.

Jeff Hebert

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

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

1.2.0.1

Updated license

1.2

remove contact email address

1.1

BSD update

some bug fixes

MATLAB Release
MATLAB 6.0 (R12)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video