Skip to main content

Embed matplotlib figures into LaTeX documents using PythonTeX

Project description

LaTeX Python figures

Given a Python script like this which draws a Matplotlib figure:

def main():

    x = np.arange(10)

    y = x**2

    plt.plot(x, y)

    plt.xlabel('$x$')

    plt.ylabel('$x^2$')

    return 'test'  # Figure filename

you can insert it into a LaTeX document like this:

\begin{figure}

    \pyfig{'test.py'}

    \caption{Test figure.}

\end{figure}

By default, the figure size defaults to \textwidth square and the font and font size match the rest of the document.

Installation

Requires a LaTeX installation (probably TeX Live 2019), PythonTeX, and Python 3.6 or greater.

Examples require latexmk.

To install the Python package:

pip3 install pythontexfigures

To install the LaTeX package into texmf-local:

sudo python3 -m pythontexfigures.install

If you don't have root access, you can install it into texmf-home instead:

sudo python3 -m pythontexfigures.install TEXMFHOME

Alternatively, call pf.print_preamble() in your pythontexcustomcode and follow with \printpythontex.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pythontexfigures-0.2.0.tar.gz (7.7 kB view hashes)

Uploaded Source

Built Distribution

pythontexfigures-0.2.0-py3-none-any.whl (10.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page