Arm*_*man 5 python pdf matplotlib
我正在尝试将衬线字体与 matplotlib 的 Latex 一起使用,不幸的是它不会在 Acrobat Reader 中显示,但在 Internet Explorer 或 Chrome 上可以。我的最小代码产生错误 StandardSymL_Slant_167 not found 并且 varepsilon 不可见,缺少什么?
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams.update(mpl.rcParamsDefault)
mpl.rcParams['text.usetex'] = True
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['times']
fig, ax = plt.subplots()
ax.set_xlabel(r'$x$ $\alpha \varepsilon$')
fig.savefig('test.pdf')
Run Code Online (Sandbox Code Playgroud)
我的环境的输出是:
import matplotlib
print(matplotlib.__version__)
3.2.0
Run Code Online (Sandbox Code Playgroud)
编辑 发现这也很奇怪:
pdffonts test.pdf
name type encoding emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
NimbusRomNo9L-Regu Type 1 Custom yes no no 21 0
CMMI10 Type 1 Builtin yes no no 13 0
NimbusRomNo9L-ReguItal Type 1 Custom yes no no 25 0
StandardSymL_Slant_167 Type 1 Builtin yes no no 17 0
Run Code Online (Sandbox Code Playgroud)
这并不是一个很好的解决方案,但我不确定除了在文本编辑器中手动编辑生成的 pdf 之外是否可以解决此问题。看来这是由 Adobe Acrobat 解析器引起的错误,因为 matplotlib 输出双精度数字,而 Type 1 字体仅支持单精度。
相关问题似乎将在即将发布的 matplotlib 3.4.0 版本中得到修复: https://github.com/matplotlib/matplotlib/issues/16087
该修复已被合并,因此更新到最新的主版本,例如 withpip install git+https://github.com/matplotlib/matplotlib.git@master应该修复它。