4.91667

4.9 | 12 ratings Rate this file 214 downloads (last 30 days) File Size: 731.75 KB File ID: #21286

matlabfrag

by Zebb Prime

 

01 Sep 2008 (Updated 15 Mar 2010)

Code covered by the BSD License  

A matlab figure to .eps and .tex file exporter, similar to LaPrint

Download Now | Watch this File

File Information
Description

matlabfrag is a function which exports a Matlab figure to .eps and .tex files for use in LaTeX/pdfLaTeX/LyX. It is inspired by LaPrint, but is intended to be more WYSIWYG, by respecting figure handles better.

Some of the advantages of matlabfrag compared to LaPrint are:
- Much more emphasis on WYSIWYG.
- Handles figures that need the OpenGL or Z-Buffer renderers.
- Text objects are sized correctly (such as with a legend).
- Tick labels are handled better.
- Reduced number of options (which could also be viewed as a disadvantage).
- A great user manual ;-)

To include the figures in LaTeX, pdfLaTeX and LyX I recommend the pstool package. More information can be found in the User Guide.

Please email any bug reports to me (see my account for more details). I'm unlikely to notice any bug reports posted in the comments.

This is version 0.6.15 of matlabfrag, uploaded 15-Mar-2010.
- Fixed a version check bug which caused it to break in r2010a, and a EPS integer overflow bug.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
LaPrint

MATLAB release MATLAB 7.8 (R2009a)
Other requirements Matlab r2007a or later.
Zip File Content  
Other Files
examples/comparison01.m,
examples/comparison02.m,
examples/ex01.m,
examples/ex02.m,
examples/ex03.m,
examples/ex04.m,
examples/ex05.m,
examples/ex06.m,
examples/ex07.m,
examples/ex08.m,
examples/ex09.m,
examples/ex10.m,
examples/ex11.m,
examples/ex12.m,
examples/ex13.m,
examples/ex14.m,
examples/ex15.m,
examples/ex16.m,
examples/ex17.m,
examples/run_all.m,
examples/test01.m,
examples/test02.m,
examples/test03.m,
examples/test04.m,
examples/test05.m,
examples/test06.m,
examples/test07.m,
examples/test08.m,
examples/test09.m,
examples/test10.m,
examples/test11.m,
examples/test12.m,
examples/test13.m,
examples/test14.m,
examples/test15.m,
examples/testing.tex,
examples/userguide.tex,
license.txt,
matlabfrag.m,
userguide.pdf
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (18)
25 May 2009 Rui

hi.. great program. congratulations
but how can i avoid the axis text having this format: " [ 'number' ] "

28 May 2009 Zebb Prime

Hi Rui,

The idea is that ['number'] gets written out to the eps file, and the tex file contains instructions (using the psfrag LaTeX package) to substitute it for the original label.

In LaTeX you can do this in two ways:
1. Load the psfrag package, and then when including the graphics, include the tex file:
\include{figure.tex}
\includegraphics{figure.eps}
-- This way only works with latex.

2. Load the psfrag and pstool packages, and use the command
\psfragfig{figure}
instead of the includegraphics command. This works for both latex (from pstool v1.2 on) and pdflatex.

Please contact me via email if you need more information.

Cheers,
Zebb

23 Jun 2009 Will Robertson  
23 Jun 2009 Kamil Wojcicki

Great job, thanks!

07 Jul 2009 James Housley

Excellent! Found it much more useable than laprint, and now can cope with transparency (use the opengl renderer).

14 Jul 2009 Matt

Hi, I'm finding this code (and pstool) to be very useful.

I would, however, like to know what font you use in matlab in order to get your legend sizing to work out in pdflatex.

16 Jul 2009 Zebb Prime

Hi Matt,

I generally leave the font as the default (Helvetica). That said, matlabfrag should work with any font you choose in Matlab.

Cheers,
Zebb

16 Sep 2009 Tor Aksel

Extraordinary work! A lot better than LaPrint, I rarely need to fight this script. However, I do occasionally get a legend box that's too small for the legend text (the right hand side of the box cuts of a few letters). Usually solved by adding a "\," or two.

19 Oct 2009 Laurin

I've been looking for exactly this program for about a year now. :)

Until now I used LaPrint for almost all of my Matlab -> Latex printing jobs. For me the biggest drawback of LaPrint is that it can only handle the Matlab "painters" renderer. In my diploma thesis I have many pcolor and isosurface plots (with nice phong lighing). With the "painters" renderer the first resulted in huge file sizes even when "downsampling" my data matrices to reasonable sizes while the latter where completely impossible to realize. With matlabfrag now even transparency works!

With matlabfrag I can now also put all my graphics in a subdirectory without manually modifying all of the tex-files like in LaPrint!

Keep up the good work!

02 Dec 2009 Paolo Bocchini

Very nice work!

17 Dec 2009 Viton Vitanis

Excellent piece of code! I'm wondering whether there is some automatic way to modify the size of the legend box during latex compilation so that it adapts to any font being used there.

26 Jan 2010 Andrey Sokolov

Is it possible to make matlabfrag output unique psfrag command numbers for every eps file? I'm including two eps files in one figure using the subfigure command, and the labels get all mixed up because some of the psfrag command numbers are the same for both files. I've tried to move the \input{*.tex} commands right before the relevant \subfigure and it worked but it had some undesirable side effect, ie the figures got stacked vertically instead of being side by side. So basically I want to include the *.tex files for both figures beforehand without messing the labels. I can change the numbers in the eps and tex files by hand of course but it's too ineffective.

28 Jan 2010 vincent ssemaganda

Thanks alot! However in my tex plots axis labels seem to get closer to axes than they are in the actual matlab pics. Is there any way to space axis labels further away from axes?

28 Jan 2010 vincent ssemaganda

This happens when I rescale the plots to be used in a sub plot

28 Jan 2010 vincent ssemaganda

Hi Andrey,

one way to solve your problem is by rescaling the eps plots to smaller sizes.
try
\includegraphics[scale = 'value < 1']{filename}

02 Feb 2010 David

I have a lot of success with matlabfrag, but I find that the print command still resizes the legend box, it is very frustrating.

If I force the rendereer to be opengl or zbuffer the legend box is in the right place but the box lines on the legend and the figure are blurry.

Please please can somebody help me with a solution for this problem?

19 Feb 2010 Hans Henrik Sievertsen

Hi,
Thanks, it is very great.
I have a problems with the location of my legend. It always seem to overlap with the xlabel when I use SouthOutside. Is there a way to avoid this?
Thanks in advance
Hans

21 Feb 2010 Zebb Prime

Hi All,

Viton: That should be possible, but I don't have time to do implement anything like that at the moment.

Andrey: That should only be necessary if you aren't grouping the figures properly. They placing \begin{psfrag} \end{psfrag} around your \include and \includegraphics.

Vincent: There isn't a way to do this using the default axis labels in matlab. You could however convert the axis labels to text objects. There are several functions that do this in the FEX, one is http://www.mathworks.com/matlabcentral/fileexchange/23841-format-tick-labels-extended (disclaimer - I haven't used this file myself)

David: What version are you using? You haven't provided enough information for me to diagnose the problem. Make sure you are using the latest version, and email me an example of the problem.

Hans: I did a quick test, and it looked the same in the document as it did on the screen. The easiest way to fix this would be to manipulate the position handles of legend, and if necessary the axis.

I also want to remind everyone that the comment section isn't a very good medium for receiving support.

Cheers,
Zebb

Please login to add a comment or rating.
Updates
10 Jun 2009

- Better handling of axis tick labels and changed the substitution text format.
- More examples.
- Improved User Guide.

21 Jun 2009

- Fixed a bug that occurred when the figure being exported had no text in it.

30 Jun 2009

- Preliminary support for the opengl and zbuffer renderers.

04 Jul 2009

Fixed support for rotated text when using the zbuffer and opengl renderers.

08 Jul 2009

Fixed some of the annoying resizing issues again.

09 Jul 2009

Improved tick label positioning.

15 Jul 2009

Improved alignment of negative xtick labels.
Legend callback should be suppressed during printing.

16 Jul 2009

Fixed the horribly broken compatibility for r2007a and r2007b.

23 Aug 2009

Fixed a bug that occurred if some (but not all) the tick labels are empty.

06 Oct 2009

- Text alignment tweaks (hopefully for the better). In particular, x-tick labels should be vertically aligned better.
- Bug fixes: z-tick label alignment and no-text detection.

13 Oct 2009

- Removed AutoTick test from axis scalings, and updated the user guide to reflect this.

26 Oct 2009

- Added a test for empty ticks, while ticklabels are not empty.
- Added sections for Legends and the 'Unable to interpret TeX string' warning in the userguide.

20 Nov 2009

Fixed a bug that occurred with [xyz]ticks set outside [xyz]lims.

11 Jan 2010

Changed default painters dpi to 3200, and fixed my broken usage of inputParser.

21 Feb 2010

Fixed a bug to do with blank strings, and a bug to do with baseline alignment.

15 Mar 2010

Fixed a version checking bug which caused it to break in r2010a, and a EPS integer overflow bug.

Tag Activity for this File
Tag Applied By Date/Time
graphics import Zebb Prime 22 Oct 2008 10:16:56
graphics export Zebb Prime 22 Oct 2008 10:16:56
latex Zebb Prime 22 Oct 2008 10:16:56
psfrag Zebb Prime 22 Oct 2008 10:16:56
eps Zebb Prime 22 Oct 2008 10:16:56
graphics Zebb Prime 22 Oct 2008 10:16:56
utilities Zebb Prime 22 Oct 2008 10:16:56
tex Zebb Prime 22 Oct 2008 10:16:56
pdflatex Zebb Prime 11 Jun 2009 09:39:33
lyx Zebb Prime 11 Jun 2009 09:39:34
latex Ismail Delice 29 Nov 2009 21:30:04
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com