View License

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

» Watch video

Highlights from
fig2texPS - Export Matlab Figure to LaTeX

4.6 | 14 ratings Rate this file 81 Downloads (last 30 days) File Size: 299 KB File ID: #25298 Version: 1.6
image thumbnail

fig2texPS - Export Matlab Figure to LaTeX


Peter Scholz (view profile)


14 Sep 2009 (Updated )

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

| Watch this File

File Information

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

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


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 (24)
19 Dec 2016 Marcin Kawka

Looks like it's no longer compatible with MATLAB versions above 2014. See this article for explanation:

05 Aug 2013 Konstantinos Margaris

19 Sep 2012 AP

AP (view profile)

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

adin (view profile)

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

Comment only
21 Oct 2011 adin

adin (view profile)

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:

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.

Comment only
16 Oct 2011 Peter Scholz

Peter Scholz (view profile)

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

Comment only
11 Oct 2011 adin

adin (view profile)

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

Comment only
22 Feb 2011 OB

OB (view profile)

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.

Comment only
22 Feb 2011 OB

OB (view profile)

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

Comment only
22 Feb 2011 OB

OB (view profile)

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

Peter Scholz (view profile)

@ Bertrand Scherrer: Thank you for your help. I have integrated your code to the latest version 0.5.2 that can be found here:
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 :-)

Comment only
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:

05 May 2010 Pia

Pia (view profile)

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! :)

Comment only
05 May 2010 Peter Scholz

Peter Scholz (view profile)

@ 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

Comment only
02 May 2010 Pia

Pia (view profile)

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


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

Petter (view profile)

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

Carlos (view profile)

16 Sep 2009 Peter Scholz

Peter Scholz (view profile)

@ Petter: You have to set
I have updated the code so that there will be given a warning in your case.

Comment only
14 Sep 2009 Petter

Petter (view profile)

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

Petter (view profile)

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

15 Sep 2009 1.1

Warning, if the 'DefaultFigureWindowStyle' is 'docked'

10 Dec 2009 1.2

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 1.3

Link updated:

05 May 2010 1.4

Enhanced Features implemented

05 May 2010 1.5

New features implemented

03 Nov 2010 1.6

    * 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