Coder Social home page Coder Social logo

hb / matplotlib2tikz Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nschloe/tikzplotlib

0.0 2.0 0.0 631 KB

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

License: GNU Lesser General Public License v3.0

Python 100.00%

matplotlib2tikz's Introduction

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

To download matplotlibtikz, go to its page on GitHub
http://github.com/nicki/matplotlib2tikz.

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 setup.py install

         or place the script matplotlib2tikz.py 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 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}


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 http://github.com/nicki/matlab2tikz.

matplotlib2tikz's People

Contributors

foucault avatar nschloe avatar olivierverdier avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.