4.72727

4.7 | 13 ratings Rate this file 102 Downloads (last 30 days) File Size: 299 KB File ID: #25298
image thumbnail

fig2texPS - Export Matlab Figure to LaTeX

by

 

14 Sep 2009 (Updated )

V053 - Conversion of a Matlab figure to a LaTeX file with PSTricks compatible macros

| Watch this File

File Information
Description

The aim of this function is to create a tex-code picture of a Matlab figure in PSTricks syntax. The tex-file picture can still be adapted after creation and may be either a standalone tex-file or a file to be included in a larger document. The LaTeX packages pstricks, pst-node, pst-plot, pst-circ and moredefs are required. An minimal example latex code is generated at each time this script is run. The matlab code is based on the fig2tex file by Ercan Solak in 2005.

You can also download the latest version on
http://fig2texps.peter-scholz.net

Supported Features:

    * 2D plots with arbitrary number of lines and patches
    * Linear and logarithmic axes and second y-axis
    * Grids, subgrids, ticks and subticks
    * Arbitrary colors, linestyles and markers
    * Labels, title, legend and colorbar
    * Annotations (TextArrows) are supported
    * GUI, where the fontsize, the plotsize and the export file can be set
    * Lines with many datapoints can be compressed in order to reduce file size and compilation time (copied from Matfig2PGF by Paul Wagenaars in 2008)
    * Convergence Triangles can be shown for logarithmic plots
    * Support of additional code in PSTricks syntax
    * Standalone Option for creating high quality cropped pdf-files

Acknowledgements

Fig2tex and Matfig2 Pgf inspired this file.

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (23)
05 Aug 2013 Konstantinos Margaris  
19 Sep 2012 AP

Excellent job

09 Nov 2011 Christopher Jones

awesome, been using fit2tex for a while, this just adds a lot of extra bling bling :)

thank you very much!

07 Nov 2011 adin

I fixed it, I think. And also add some other things. If someone is interested look in here: http://pastebin.com/xK6KxxBT

21 Oct 2011 adin

Hi Peter, I made some changes to your script regarding the use of pdflatex, now the files created use ifpdf package to compile for pdflatex and latex. I didn't know where to put it, so you can find it here: http://pastebin.com/cHGqD9a5

Also, I found a bug when you have points outside of the axis size, in which those points are removed from the plot.

I'm not sure if my approach is correct or not, but did the job for my test scenarios. Also, it may help others.

16 Oct 2011 Peter Scholz

@adin: I can't provide any support and/or changes on the script no longer. I have never tested the \usepackage[pdf]{pstricks} version of pstricks but it could work.
Regarding the one/two column document: I recommend to export two versions of the figure, one for each version of the document. The best way is to write the default configuration to the "globals" struct and run the script with "fig2texPS(fignum,globals)".

11 Oct 2011 adin

Hi, I love your script. It work really good. However, I'm struggling with a couple of things.
First, it would be great if you add an option for pdflatex. You can compile it using \usepackage[pdf]{pstricks} instead of the normal pstricks header that you already have. However, this only works for the stand alone version. Which creates my second issue.

The thing is that if you have a two column document, the size of the document is fixed, is there a way to make it change with the \linewidth. So it will be relative to one or two column documents.

Thanks for your work. :)

21 Apr 2011 Antoine Haarscher

Hi, I cannot run this program for a pcolor figure. Is it my mistake or it is simply impossible?
Thank you

22 Feb 2011 OB

The marker legend problem is solved. It was not the script. (fig2texPS is a great script!!) It was XeLaTeX !! Compiled with LaTeX and converted with dvips and epstopdf, I obtained a perfect PDF graphic file. Wondeful.

22 Feb 2011 OB

This is a great script!! I love this.

By the way, when markers present, the legend does not display markers. Could you fix this?

Maybe you test with this:

x = linspace(0,2,10);
y = exp(x);
plot(x,y,'bo-');
legend('\exp(x)');
fig2texPS;

22 Feb 2011 OB  
06 Sep 2010 Jeff Tuhtan

Worked well, thank you for sharing this script. The stand alone option is a great feature!

10 Jun 2010 Peter Scholz

@ Bertrand Scherrer: Thank you for your help. I have integrated your code to the latest version 0.5.2 that can be found here:
http://fig2texps.peter-scholz.net
The borders of the text boxes are now also shown. But there is still some finetuning to implement, e.g. an automatic linebreak for longer text. I will do that when I'll find some time for that :-)

09 Jun 2010 Bertrand Scherrer

Dear Peter,

Thank you for making this script available. It is very useful.

I have slightly modified your script to include text box annotations in the exported figures. I posted the file and a little test file at: http://www.music.mcgill.ca/~scherrer/fig2texPS_wTextBoxes

05 May 2010 Pia

Ah, it was the version number that was the problem - of course I downloaded the one from this page instead of going to your page to get the most recent one - doh!

Thank you very much for the help - you're a life saver with this script! :)

05 May 2010 Peter Scholz

@ Pia: I have tested your given errorbar with the newest version V.0.5.1 and it works fine without errors. Please test again with the same version and send me your tex-file if it still not works. Peter

02 May 2010 Pia

I have trouble exporting errorbar plots. Do the package support these? A simple plot like

errorbar(1:10,sin(1:10),0.1*sin(1:10))

exports fine (apparently, not errors at least), but after compiling, my DVI viewer simply stalls with weird errors. If I try to convert the dvi document to a pdf, my GhostScript simply tells me there was an unrecoverable error, and that it stopped.. :(

22 Dec 2009 Petter

As I've said before: it would be really nice if there was an option to export to a stand alone tex file with correct paper sizes that then could be converted to a PDF via ps2pdf. This way, users of pdflatex can also use this package.

15 Dec 2009 Alan Kennedy

Great submission! very much what I was looking for - am having problems though adding text to the figure itself (using Matlab's text() command) - and ignore my last rating, that was an accident! 5 stars.

25 Nov 2009 Carlos  
16 Sep 2009 Peter Scholz

@ Petter: You have to set
set(0,'DefaultFigureWindowStyle','normal')
I have updated the code so that there will be given a warning in your case.

14 Sep 2009 Petter

Couldn't you create a standalone .tex file (with paper sizes etc.)which could be compiled using latex/ps2pdf into a separate pdf file containg the figure.

Then we pdfLatex users could include this file into our documents.

14 Sep 2009 Petter

I cannot run this file

??? Error using ==> figure
Error using ==> figure
Cannot set DockControls to 'off' while WindowStyle is 'docked'

Error in ==> fig2texPS at 891
fig.figh=figure('Name','Figure that will be converted to TeX',...

Might be a conflict with
set(0,'DefaultFigureWindowStyle','docked');

Updates
15 Sep 2009

Warning, if the 'DefaultFigureWindowStyle' is 'docked'

10 Dec 2009

Changes to Version 0.42:
* More possible locations for the legends
* Linewidths of the global struct can now also be strings
* Linestyles adapted
* Enhancements for TextArrows
* Questiondialog, if the tex file already exists
* Small bugfixes

11 Dec 2009

Link updated: http://fig2texps.peter-scholz.net

05 May 2010

Enhanced Features implemented

05 May 2010

New features implemented

03 Nov 2010

Changes:
    * dataplot -> psline replaced, option linejoin=1 introduced
    * marker more bold
    * enhancement for patches which are cut at the axes limits
    * Colorbar enhancement
    * Support of TextBoxes
    * Small bugfixes

Contact us