User Tools

Site Tools


Creating PDF files from Matplotlib using the PGF backend

Since matplotlib in Fedora 25 seems to be having some font issues when using latex fonts and creating pdf or ps files, a workaround is needed. Luckily, PDF files can also be created using the PGF backend. See for details

Basically, include these lines in the python script and saving to pdf will work:

from matplotlib.backends.backend_pgf import FigureCanvasPgf
from matplotlib.backend_bases import register_backend
register_backend('pdf', FigureCanvasPgf)

If you need customization of the fonts, that may have to be done through the pgf settings; the page linked above has some examples.

linux/matplotlib_pgf_backend.txt · Last modified: 2016/12/22 10:39 by jansen