# nschloe/matplotlib2tikz

### Subversion checkout URL

You can clone with
or
.
A converter that takes a matplotlib figure and spits out a TikZ (Pgfplots) figure for smooth integration into LaTeX.
Python Makefile
`Support for marker_edge_color/marker_face_color that is not a string, but a rgb-tuple`
latest commit 26e0696711
authored
 Failed to load latest commit information. doc Feb 25, 2014 helpers Jan 24, 2014 test Mar 5, 2014 .gitignore Oct 14, 2010 COPYING Mar 26, 2010 ChangeLog Mar 26, 2010 README.md Aug 28, 2014 matplotlib2tikz.py Mar 12, 2015 setup.py Jan 24, 2014

# matplotlib2tikz

This is matplotlib2tikz, a Python script for converting matplotlib figures into native Pgfplots (TikZ) figures.

### Installation

1. Place the matplotlib2tikz script in a directory where Python can find it (e.g., `\$PYTHONPATH`). You can install it systemwide with

``````sudo python setup.py install
``````

or place the script `matplotlib2tikz.py` into the directory where you intend to use it.

2. Make sure that your LaTeX installation includes the packages

• TikZ (aka PGF, >=2.00), and
• Pgfplots (>=1.3).

### Usage

1. Generate your matplotlib plot as usual.

2. Instead of pyplot.show(), invoke matplotlib2tikz by

``````tikz_save( 'myfile.tikz' );
``````

to store the TikZ file as myfile.tikz. Load the libary with:

``````from matplotlib2tikz import save as tikz_save
``````

Optional: The scripts accepts several options, for example `height`, `width`, `encoding`, and some others. Invoke by

``````tikz_save( 'myfile.tikz', figureheight='4cm', figurewidth='6cm' )
``````

IMPORTANT: Height and width must be set large enough; setting it too low it may result in a LaTeX compilation failure such as - Dimension Too Large, or - Arithmetic Overflow (see information about these errors in the manual of Pgfplots)

To specify the dimension of the plot from within the LaTeX document, try

``````tikz_save('myfile.tikz',
figureheight = '\\figureheight',
figurewidth = '\\figurewidth'
)
``````

and in the LaTeX source

``````\newlength\figureheight
\newlength\figurewidth
\setlength\figureheight{4cm}
\setlength\figurewidth{6cm}
\input{myfile.tikz}
``````
3. 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:

``````\usepackage{tikz}
\usepackage{pgfplots}
``````

Optionally, to use features of the latest Pgfplots package (as of Pgfplots 1.3), insert

``````\pgfplotsset{compat=newest}
``````