【问题标题】:How do I get rid of these artifacts (matplotlib with LaTeX)如何摆脱这些工件(matplotlib with LaTeX)
【发布时间】:2014-02-26 15:59:19
【问题描述】:

在运行以下最小示例时,我在 LaTeX 渲染的表达式中得到了奇怪的 J 形伪影。

import matplotlib.pyplot as plt
from matplotlib import rc

rc('font',**{'family':'serif','serif':['Times']})
rc('text', usetex=True)
rc(('xtick','ytick','axes'), labelsize=12.0)
rc(('legend'), fontsize=8.0)

fig=plt.figure(figsize=(4,3))
ax1 = fig.add_subplot(111)

ax1.plot([0,1],[0,1],label=r'$\propto x^1$')
ax1.set_xlabel(r'$x$')
ax1.set_ylabel(r'$\sum_i \chi_i$')

ax1.legend()

fig.tight_layout()
plt.savefig('minimal.pdf')

输出:

我怎样才能摆脱它们?

【问题讨论】:

  • 这可能是因为您的系统上没有类似于Times 的具有适当符号的字体。如果删除设置字体系列的第一行 rc 会发生什么? (您的示例在我的系统上完美运行,值得。我猜'serif':['Times'] 正在为您提供 Times New Roman,它没有正确的符号。)

标签: python-3.x matplotlib latex


【解决方案1】:

正如 Joe Kington 在他的评论中指出的那样,摆脱伪影的方法是使用具有正确符号的字体。

在最小的示例中,删除 rc('font',**{'family':'serif','serif':['Times']}) 可以解决问题。

【讨论】:

    猜你喜欢
    • 2017-01-25
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    相关资源
    最近更新 更多