-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
star (*) symbol in text box cuts off bottom of text when saved #15313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I can confirm this on my machine. import matplotlib.pyplot as plt
fig, ax = plt.subplots(1,1)
ax.text(0.5, 0.5, '$S_{x} Math$',
transform=ax.transAxes)
ax.text(0.5, 0.2, '$S_{*} Math$',
transform=ax.transAxes)
ax.text(0.2, 0.35, '$S_{*} Math_{p}$',
transform=ax.transAxes)
plt.savefig('test1.png', dpi=200) It looks like somehow the lower extent is being set by the subscript if there is one, and not the minimum of the subscript and the rest of the text. Note if you put a bigger subscript in, all is well. |
So what's the difference? |
Oh, it's the dpi. Would be good to state it explicitely in the code, because matplotlib's default dpi=100 works fine it seems. |
I dunno. So far, |
Not sure why it ends up OK for 100 dpi, but yes thats true. Is matplotlib's default really 100 dpi? Regardless, the font metrics are incorrect so thats probably the root of the problem |
It seems that at this point matplotlib/lib/matplotlib/mathtext.py Line 200 in 27931d4
Also, it's not only the height that's wrong, but in general the position, maybe one is the consequence of the other though. |
fwiw this doesn't happen with mplcairo either; I have some plan to just lift the mplcairo mathtext code to replace MathtextBackendAgg... |
Isn't it that Cairo can directly render the glyphs, while Agg needs a FTImage? How would you replace that? (Matplotlib's internal Cairo backends also work fine in this context here.) |
It doesn't really matter whether the rendering is done directly or via FT2Image; I think the important point is to repro the logic of rounding fractional glyph positions. |
The issue here is unrelated to rounding. It seems to be in the logic that places the image. If you replace this line matplotlib/lib/matplotlib/mathtext.py Line 194 in 27931d4
by
i.e. don't subtract the "original depth", the result will be which shows the correct image for the text that does not go below the baseline. But somehow you need to account for the depth, or else the image where text does go below the baseline will be placed wrongly aligned. |
So should it just be that oy is changed? |
I don't think so, because I wouldn't know which quantity to use to discriminate the two cases. But maybe someone else has an idea, in which case this is the code to reproduce above images.
|
Yeah somehow the baseline has been set to the bottom of the subscript but I’ve not been able to track how that gets decided. Maybe in the image creation? |
An unhelpful data point: this has been like this since at least 2.0. I have trouble compiling anything older.... |
It was also present earlier, but in 1.x the default math font was computer modern, which puts the asterix below the baseline and hence one wouldn't have noticed. |
See #15339 (still needs some work and description). |
Bug report
Bug summary
When using the star (*) symbol in a
text
box, it cuts off the bottom of the text when saved (savefig
). This is only the case whenusetex=False
inrcParams
.Code for reproduction
You can see the bottom of the text box is cut off. Whereas this plots fine:
Matplotlib version
print(matplotlib.get_backend())
): TkAggmatplotlib installed from pip
cycler==0.10.0
kiwisolver==1.1.0
numpy==1.17.2
pyparsing==2.4.2
python-dateutil==2.8.0
six==1.12.0
The text was updated successfully, but these errors were encountered: