Skip to content
Egon Geerardyn edited this page Mar 20, 2018 · 11 revisions

This is the wiki page of matlab2tikz, a MATLAB script to convert MATLAB figures to TikZ figures for easy and consistent inclusion into LaTeX documents.

Go get it!

You find the download section on MATLAB Central; if you like the script, you can rate it on this page to make it stick out more to other users.

Core functionality

As of now, matlab2tikz does not implement the conversion of all possible MATLAB figures. In particular, 3D plots are not yet supported; however, with the advent of Pgfplot 1.3, this goal came into reach. If you have a nice 2D plot, matlab2tikz might just do what you want it to. Among the supported features right now are:

  • most axes properties (including logarithmic scaling),
  • grids,
  • line plots (including markers line styles),
  • contour(f) plots,
  • bar plots (stacked, grouped, histgrams),
  • error bars,
  • stem plots,
  • stairs plots,
  • quiver (arrow) plots,
  • colorbars,
  • legends,
  • images,
  • subplots (with exact alignments).
  • zplane plots
  • frequency response plots

Moreover, there is basic support for

  • rose plots,
  • compass plots,
  • polar plots.

Workflow

  1. Place the matlab2tikz script in a directory where MATLAB can find it. (the current directory, for example), and make sure that your LaTeX installation includes recent versions of the packages TikZ and pgfplots.
  2. Generate your plot in MATLAB.
  3. Invoke matlab2tikz by
    >> matlab2tikz( 'myfile.tikz' );
    As of version 0.0.4, matlab2tikz supports several options given on the command line. For example
    >> matlab2tikz( 'myfile.tikz', 'height', '4cm', 'width', '62mm' );
    sets the (LaTeX) width and height of the picture. This can also be used to set the dimension from within LaTeX; simply set
    >> matlab2tikz( 'myfile.tikz', 'height', '\fheight', 'width', '\fwidth' );
    and then include the file into LaTeX by
\newlength\fheight
\newlength\fwidth
\setlength\fheight{4cm}
\setlength\fwidth{6cm}
\input{myfile.tikz}
  1. Add the contents of myfile.tikz into your LaTeX source code; a convenient way of doing so is to use \input{/path/to/myfile.tikz}. Also make sure that at the header of your document the packages TikZ and pgfplots are included:
\documentclass{...}
[...]
\usepackage{pgfplots}
% recommended as of Pgfplots 1.3:
\pgfplotsset{compat=newest}
[...]
\begin{document} [...] 

Feedback

If you experience bugs or have feature requests, please do not hesitate to file an issue right here on GitHub. The issue should include the following:

  • A minimal MATLAB code reproducing your issue. Either with generic data or your data uploaded as a zip file
  • A comparison of the generated pdf (if it compiled) and the original MATLAB figure (export as jpeg)
  • Which version of matlab2tikz are you using and which version of pgfplots do you have. Please check the FAQ if you dont know where to get that information.