![Matplotlib pgf 后端针对所有图返回“LaTeX 返回错误,可能是缺少字体或序言中有错误”](https://linux22.com/image/305849/Matplotlib%20pgf%20%E5%90%8E%E7%AB%AF%E9%92%88%E5%AF%B9%E6%89%80%E6%9C%89%E5%9B%BE%E8%BF%94%E5%9B%9E%E2%80%9CLaTeX%20%E8%BF%94%E5%9B%9E%E9%94%99%E8%AF%AF%EF%BC%8C%E5%8F%AF%E8%83%BD%E6%98%AF%E7%BC%BA%E5%B0%91%E5%AD%97%E4%BD%93%E6%88%96%E5%BA%8F%E8%A8%80%E4%B8%AD%E6%9C%89%E9%94%99%E8%AF%AF%E2%80%9D.png)
我花了几个小时尝试让 PGF 后端工作。我尝试使用 xelatex,但它根本无法运行。
现在我做了这个例子:
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use("pgf")
pgf_with_rc_fonts = {
"pgf.texsystem": "pdflatex"
}
mpl.rcParams.update(pgf_with_rc_fonts)
import matplotlib.pyplot as plt
plt.figure(figsize=(4.5,2.5))
plt.plot(range(5))
plt.savefig('figure.pgf')
这会引发错误。我马上就会讲到。但是,如果我删除 plt.savefig('figure.pgf'),错误就会消失。终端返回的输出是:
Traceback (most recent call last):
File "Dokumenter/fys2130/oblig4/test.py", line 13, in <module>
plt.savefig('figure.pgf')
File "/home/marius/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 577, in savefig
res = fig.savefig(*args, **kwargs)
File "/home/marius/anaconda/lib/python2.7/site-packages/matplotlib/figure.py", line 1470, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/home/marius/anaconda/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2194, in print_figure
**kwargs)
File "/home/marius/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_pgf.py", line 835, in print_pgf
self._print_pgf_to_fh(fh, *args, **kwargs)
File "/home/marius/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_pgf.py", line 814, in _print_pgf_to_fh
RendererPgf(self.figure, fh),
File "/home/marius/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_pgf.py", line 422, in __init__
self.latexManager = LatexManagerFactory.get_latex_manager()
File "/home/marius/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_pgf.py", line 232, in get_latex_manager
new_inst = LatexManager()
File "/home/marius/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_pgf.py", line 322, in __init__
raise LatexError("LaTeX returned an error, probably missing font or error in preamble:\n%s" % stdout)
matplotlib.backends.backend_pgf.LatexError: LaTeX returned an error, probably missing font or error in preamble:
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian)
restricted \write18 enabled.
**---! /home/marius/.texmf-var/web2c/pdftex/pdflatex.fmt doesn't match pdftex.pool
(Fatal format file error; I'm stymied)
我的matplotlib版本是1.4.2。
我的问题是,我该如何解决这样的问题?
我不知道从哪儿开始。