Skip to main content

A package to save matplotlib figures for easy inclusion in LaTeX.

Project description

MatpLaTeX

MatpLaTeX lets you save a matplotlib Figure as a combination of a pdf file containing the graphics and a tex file containing the text. With this, text in the figure will automatically use the typeface, size and other settings of the surrounding text.

Installation

For the development version, clone this directory, cd into it and run

pip install .

Requirements:

  • python >= 3.10 (If someone asks I may add support for earlier versions.)
  • matplotlib >= 3.5
  • beartype

Basic Usage

To save a figure, simply use

matplatex.save(fig, "myfig")

this will create two files named myfig.pdf and myfig.pdf_tex. Add

\newsavebox\figurebox

to your LaTeX preamble and include the figure in your document with

\def\figurewidth{<width>}}
\input{myfig.pdf_tex}

LaTeX commands such as \small and \textbf{} will affect the text in the expected way.

More Options

If you don't like the commands \figurebox and \figurewidth, you can change them to something else by passing the keyword arguments 'boxname' or 'widthcommand' to matplatex.save.

Limitations

  • Characters which need to be escaped in LaTeX must also be escaped in the plot.

Why not …

… adjust the plot settings in a matplotlib style sheet?

You’d need to recreate every figure each time you make a change.

… use tikzplotlib?

Tikzplotlib is great for simple figures, but fails to accurately recreate more complex ones, or ones with too much data. MatpLaTeX is meant to cover a different usecase that tikzplotlib rather than compete with it.

… use pgfplots from the getgo?

I like python.

… spend time on actual work rather than on tiny details nobody cares about anyway?

I care.

Motivation

You've probably been there: you made a nice figure and now you want no include it in your LaTeX document. But the text is too small. And the font doesn't match.

You open the matplotlib documentation and adjust all the necessary settings for the figure to look right, perfectly at home in your manuscript.

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

matplatex-0.2.3.tar.gz (19.2 kB view hashes)

Uploaded Source

Built Distribution

matplatex-0.2.3-py3-none-any.whl (20.7 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