Professional matplotlib plots for LaTeX documents. Transform ugly default plots into publication-ready figures with just two lines of code.
Built on the foundational work by Jack Kelly and enhanced for modern research workflows. This package has been successfully used in multiple publications from our sustainability research lab.
Default matplotlib produces plots that look amateur and clash with your beautiful LaTeX documents. Latexify fixes this by providing:
- Font matching - Uses same fonts as your document
- Proper sizing - Automatic figure dimensions for single/double columns
- LaTeX symbols - Perfect math rendering with
r'$\sin(x)$' - Clean axes - Removes chart junk and visual clutter
- No scaling needed - Just use
\includegraphics{plot.pdf}directly
The difference is dramatic. Here's a complete LaTeX document showing default matplotlib vs. latexify:
Key improvements shown:
- Font matching: Latexify plots use the same fonts as document text
- Clean axes: No chart junk, professional appearance
- LaTeX symbols: Perfect math rendering with
$\sin(x)$,$\cos(x)$ - Proper sizing: No manual scaling needed in
\includegraphics{} - Column optimization: Automatic sizing for single and double column layouts
pip install git+https://github.com/sustainability-lab/latexify.gitOr copy latexify.py to your project.
import latexify
import matplotlib.pyplot as plt
import numpy as np
# Setup for your document
latexify.latexify(columns=1) # or columns=2
# Plot with LaTeX symbols
x = np.linspace(0, 2*np.pi, 100)
plt.plot(x, np.sin(x), label=r'$\sin(x)$')
plt.plot(x, np.cos(x), label=r'$\cos(x)$')
plt.xlabel(r'$x$ (radians)')
plt.ylabel(r'Amplitude')
plt.legend()
# Clean up and save
latexify.format_axes(plt.gca())
latexify.save_fig('plot.pdf')In your LaTeX document:
\begin{figure}[htbp]
\centering
\includegraphics{plot.pdf} % No width scaling needed!
\caption{Beautiful, professional plot.}
\end{figure}Each example shows how latexify automatically adapts to different academic document formats with appropriate font sizes, spacing, and styling. The examples include:
- Code snippets with proper Python string quotes
- 3 subplot layouts optimized for each format
- Before/after comparisons showing the improvement
- Complete LaTeX source for easy adaptation
Configure matplotlib for LaTeX output.
Parameters:
columns: 1 for single column, 2 for double column layoutslargeFonts:Truefor presentations,Falsefor papersfig_width/fig_height: Override automatic sizing (inches)
Clean up axes by removing chart junk and applying professional styling.
Save figure with optimal settings for LaTeX inclusion.
latexify.latexify(columns=1) # Single column
latexify.latexify(columns=2) # Double column latexify.latexify(fig_width=3.4, fig_height=2.3)
plt.rcParams.update({'font.size': 8})latexify.latexify(fig_width=3.3, fig_height=2.2)
plt.rcParams.update({'font.size': 9})latexify.latexify(largeFonts=True, fig_width=4.5, fig_height=3.0)
# Automatically uses larger fonts suitable for presentationsNeed custom dimensions? Here's how to find your template's column width:
Add this to your document and check the output:
\the\columnwidth % Shows column width in points
\the\textwidth % Shows text width in pointsConvert points to inches: width_inches = points / 72.27
\usepackage{ruler}
\begin{document}
\ruler % Shows ruler with measurements| Template | Single Column | Double Column |
|---|---|---|
| Standard Article | 3.5" | 7.0" |
| IEEE | 3.4" | 7.0" |
| ACM | 3.3" | 6.75" |
| Springer | 3.35" | 6.8" |
Then use: latexify.latexify(fig_width=YOUR_WIDTH)
latexify.latexify(columns=1)
plt.rcParams.update({
'font.size': 9, # Base font size
'axes.labelsize': 9, # Axis labels
'legend.fontsize': 8, # Legend
'xtick.labelsize': 8, # Tick labels
'ytick.labelsize': 8
})fig, axes = plt.subplots(2, 2, figsize=(6.5, 5))
for ax in axes.flat:
ax.plot(data)
latexify.format_axes(ax) # Clean each subplotLatexify automatically uses the golden ratio (≈1.618) for aesthetically pleasing proportions:
# This gives you golden ratio height automatically
latexify.latexify(fig_width=3.5) # height = 3.5/1.618 ≈ 2.16"- matplotlib >= 3.0.0
- numpy >= 1.15.0
- LaTeX installation (for math rendering)
MIT







