繁体   English   中英

Matplotlib 生成的 pdf 无法被 Acrobat Reader 打开

[英]Matplotlib generated pdf cannot be opened by Acrobat Reader

我正在尝试在 matplotlib 中使用带有乳胶的衬线字体,不幸的是它不会在 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')

acrobat pdf上的错误

我的环境的输出是:

import matplotlib
print(matplotlib.__version__)
3.2.0

编辑发现这也很奇怪:

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

这不是一个很好的解决方案,但我不确定在文本编辑器中手动编辑生成的 pdf 是否可行。 这似乎是由 Adob​​e Acrobat 解析器引起的错误,因为 matplotlib 输出双精度数字,而 Type 1 字体仅支持单精度。

似乎将在即将发布的 matplotlib 3.4.0 版本中修复的相关问题: https ://github.com/matplotlib/matplotlib/issues/16087

该修复已被合并,因此更新到最新的 master,例如使用pip install git+https://github.com/matplotlib/matplotlib.git@master应该修复它。

据我了解,希腊字体的问题。 有趣的是,win os 通常会出现问题...

试试win改编版,请:

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']
mpl.rcParams['font.family'] = ['times new roman']

fig, ax = plt.subplots()
ax.set_xlabel(r'$x$ $\alpha \varepsilon$')
fig.savefig('test.pdf')

我有一个类似的问题,我没有从 pdf 阅读器那里得到任何信息警告,但 Chrome 可以显示 pdf。 对我来说,解决方案是更改设置为零的linewidth 更具体地说,在我的情况下fill_between

plt.fill_between(steps, lower_line, top_line,
                                 linewidth=0.01, # CANNOT BE ZERO, GIVES ERRORS IN PDF READERS
                                 linestyle='dashdot',
                                 antialiased=True,
                                 )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM