在标签中使用下划线实际上不会创建下划线。我不知道发生了什么事
最低工作示例:
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
})
字体
cmr10
是罪魁祸首。这是一种与matplotlib捆绑的字体,但实际上不包含下划线字符。来自FontForge:从this website开始,下划线的unicode字符是
U+005f
,我们可以从上图中看到,它被映射到overdot。这就是为什么我们在标签中看到的是一个过度标记,而不是下划线。我将提交一个与matplotlib有关的问题。希望我们能正确修补字体编辑github issue is here(#16995)
解决方案:
事实证明,TeX最初并没有下划线编码
因此,唯一的解决办法是使用不同的字体
相关问题 更多 >
编程相关推荐