在标签中使用下划线实际上不会创建下划线。我不确定发生了什么
最小工作示例:
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()
这是我的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
})
答案 0 :(得分:3)
字体cmr10
是元凶。这是与matplotlib捆绑的字体,但实际上不包含下划线字符。从FontForge:
在this website中,下划线的unicode字符为U+005f
,我们可以从上面的图像映射到上划线的形式看到。这就是为什么我们在标签上看到下划线而不是下划线的原因。我将通过matplotlib提交有关此问题的问题。希望我们可以正确修补字体。
编辑:github issue is here(#16995)
事实证明,TeX最初没有下划线编码。
因此唯一的解决方案是使用其他字体。