Skip to content
This repository

A converter that takes a matplotlib figure and spits out a TikZ (Pgfplots) figure for smooth integration into LaTeX.

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

To download matplotlibtikz, go to its page on GitHub

The workflow is as follows.

  0.) a) Place the matplotlib2tikz script in a directory where Python can find
         it (e.g., $PYTHONPATH).

	 You can install it systemwide with

           sudo python install

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

      b) Make sure that your LaTeX installation includes the packages

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

  1.) Generate your matplotlib plot as usual.

  2.) Instead of, 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

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

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

     eHeight 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
                  figureheight = '\\figureheight',
                  figurewidth = '\\figurewidth'

      and in the LaTeX source

  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


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


If you experience bugs, would like to contribute, have nice examples of what
matplotlib2tikz can do, or if you are just looking for more information, then
please visit the web page of matplotlib2tikz
Something went wrong with that request. Please try again.