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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for matplatex-0.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 341ef48ccfc2733747ab342f17b23bfec7099628e01ea1702eeb85c542264216 |
|
MD5 | 083e1d52f0783f4246c7f2a93f3672b4 |
|
BLAKE2b-256 | 9f952055524530e4cd46d178b9d9fc84d631510fdbd42ffaafcbe44b34a8a2eb |