Issue
Using underscores in a label does not actually create an underscore. I'm not sure what's happening
Minimum Working Example:
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()
Edit:
Here are my 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
})
When I run without this, I get it working correctly:
Solution
The font cmr10
is the culprit. This is a bundled font with matplotlib, but it actually doesn't include an underscore character. From FontForge:
From this website, the unicode character for underscore is U+005f
, which we can see form the above image is mapped to the overdot. This is why we're seeing an overdot in the label instead of the underscore. I'll be submitting an issue with matplotlib about the issue. Hopefully we can get the font patched correctly.
Edit: The github issue is here (#16995)
Solution:
It turns out that TeX did not originally have encodings for underscores.
So the only solution is to use a different font.
Answered By - James Wright
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.