File Exchange

image thumbnail


version 1.2 (26.2 KB) by

Convert figures to PGF files that can be included in LaTeX documents.

12 Ratings



View License

Matfig2PGF is script that allows users to convert MATLAB figures to PGF <>. PGF figures can be included in a LaTeX document using the PGF macro package. The PGF package works with most important LaTeX backends (such as pdfTeX and Dvips). Using Matfig2PGF all text in the figure is typeset by LaTeX, so it blends in nicely with the rest of the document.

- 2D plots
- subplots
- histograms
- linear and logarithmic axes
- grids
- legends
- line styles and plot marks
- resulting pgf file can be used in LaTeX and pdfLaTeX

The current version is 0.3.9

Comments and Ratings (16)


Alon (view profile)

Did anyone do the exercise of converting this code to Matlab 2016b? The figure handling has changed pretty radically and get(child_handle,'Type') within handle_all_children often returns different new types, such as 'legend'.
Any suggestions on how to tackle this would be helpful.


Georg (view profile)

Works like a charm! Makes figures in latex look superb.

One little flaw though: When I overlay to axes, one containing an imge with transparency, the output is two PNGs which are all black.

Dan Miller

My figures now look gorgeous.


Lukas (view profile)

Oh no, my comment is at the wrong position and I don't know how to delete it. Sorry.

Juan Pablo

I'm running Matlab (R2007b) on Debian (Lenny) and it just worked out of the box.

Jason Wigg

A very, very nice contribution! Really wish I had found it earlier.

My only suggestion would be to implement something to check axes titles and legends to escape out LaTeX key characters. For example I have a plot with the title 'Voltage & Current against Time', which errors out when converted to pgf, as it needs to be 'Voltage \& Current against Time'.

One of the best tools I've seen for figure conversion. I also would like to see an update to allow for figure width control from within latex, if it's not to difficult to implement. Capability for 3D plots would also improve this tool.


Petter (view profile)

I wish that it was possible to set the figure width from within the LaTeX document.


Loginatorist (view profile)

I like the name!

a s

Very nice contribution.

A few remarks, though:

* In the subfunction draw_patch, scaled indexed colouring is taken care of for edges, but not for faces. I had to add conversion to direct index to avoid errors.

* In some patch plots the axis grid should be visible above the patch object. As it is now, grid lines disappear.

* Does not recognize image objects and surface objects.

* My Matlab has started closing down without warning when I use this function. Might be a coincidence, though.

Will keep using this, it works brilliantly for ordinary line plots.

Peadar Grant

Very nice indeed - this must have taken a lot of work. I only wish I discovered this earlier.

Mukhtar Ullah

Very useful. It would be very nice to have two more features: 1) latex allowed in the tick-labels. 2) multiple axes in the same figure.

mathan mathan


Martin Heller

Very nice tool!

It would be great if draw_patch could take CData into account if FaceColor=flat.

Dietrich Brunn

Excellent Tool - like it

Shengshan Cui

I just want to see this work is awesome! It frees me from touching up Matlab figures or using Gnuplot to get high quality figures. In addition, with more and more LaTeX users using PGF, this work will be appreciated by more people.

Thanks for the excellent work!



New version with a bug fix.


New version with a couple of bug fixes.

There's an error in the file I uploaded about an hour ago. Please ignore that file and use this one.

New version (0.3.5)

New version (0.3.4)

New version with a few bugfixes

New version with bug fix

Updated to version 0.3.1

New version: Matfig2PGF 0.3


MATLAB Release
MATLAB 7.5 (R2007b)

Inspired: fig2texPS - Export Matlab Figure to LaTeX

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

» Watch video