LaTeX TypesettingΒΆ

By default, matplotlib uses mathtext to interpret LaTeX strings. It usually works quite well, but it is not perfect. For example, mathtext does not distinguish between textstyle and displaystyle, so fractions look too small and it is not possible to make integral signs smaller. Fortunately, figure text can be typeset using true LaTeX. Typesetting with LaTeX is significantly slower when saving as a pdf, but sometimes it is needed to get things right.

import clearplot
import clearplot.plot_functions as pf
import numpy as np

x = np.arange(0,10,0.01)
y = np.sqrt(x)

pf.plot('math_text_typesetting.png', x, y, \
    x_label = ['\int_0^x \exp\left[\hat{x}\right]\,\mathrm{d}\hat{x}'], \
    y_label = ['\frac{P}{A}', 'GPa'])
    
clearplot.params.use_latex(True)
[fig, ax, curves] = pf.plot('LaTeX_typesetting.png', x, y, \
    x_label = ['\int_0^x \exp\left[\hat{x}\right]\,\mathrm{d}\hat{x}'], \
    y_label = ['\displaystyle \dfrac{P}{A}', 'GPa'])

Math Text Typesetting:

examples/LaTeX_typesetting/math_text_typesetting.png

LaTeX Typesetting:

../../_images/LaTeX_typesetting.png