标签中的下划线不呈现

2024-09-24 12:22:15 发布

您现在位置:Python中文网/ 问答频道 /正文

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

最低工作示例:

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


Tags: test示例plotrangeplt标签variablelabel
1条回答
网友
1楼 · 发布于 2024-09-24 12:22:15

字体cmr10是罪魁祸首。这是一种与matplotlib捆绑的字体,但实际上不包含下划线字符。来自FontForge:

enter image description here

this website开始,下划线的unicode字符是U+005f,我们可以从上图中看到,它被映射到overdot。这就是为什么我们在标签中看到的是一个过度标记,而不是下划线。我将提交一个与matplotlib有关的问题。希望我们能正确修补字体

编辑github issue is here(#16995)

解决方案:

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

因此,唯一的解决办法是使用不同的字体

相关问题 更多 >