标签中的下划线不呈现

时间:2020-04-01 15:26:26

标签: python matplotlib

在标签中使用下划线实际上不会创建下划线。我不确定发生了什么

最小工作示例:

variable = range(5)
plt.plot(variable, variable, label='test_underscore')
plt.plot(variable, variable, label='escape\_underscore')
plt.plot(variable, variable, label=r'rawtest_underscore')
plt.plot(variable, variable, label=r'rawescape\_underscore')
_=plt.legend()

enter image description here

编辑:

这是我的rcParams

plt.rcParams.update({
            'font.family': 'serif',
            'font.serif': 'cmr10',
            'mathtext.fontset': 'cm',
            'axes.unicode_minus': False,
            'font.size': 11,
            'figure.dpi': 200,
            'lines.linewidth': 0.5,
            'axes.grid': True
})

当我不这样做时,我将使其正常工作: enter image description here

1 个答案:

答案 0 :(得分:3)

字体cmr10是元凶。这是与matplotlib捆绑的字体,但实际上不包含下划线字符。从FontForge:

enter image description here

this website中,下划线的unicode字符为U+005f,我们可以从上面的图像映射到上划线的形式看到。这就是为什么我们在标签上看到下划线而不是下划线的原因。我将通过matplotlib提交有关此问题的问题。希望我们可以正确修补字体。

编辑:github issue is here(#16995)

解决方案:

事实证明,TeX最初没有下划线编码。

因此唯一的解决方案是使用其他字体。

相关问题