You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the LaTex text rendering, label fonts with sizes x-small are being stretched.
Details
Changing the font size to small results in correct font rendering, but I noticed that the small and x-small fonts use up the same amount of vertical space, so it seems like the font is just vertically stretched in the x-small case.
See the images below.
Output using font size x-small and PDF backend:
Output using font size small and PDF backend:
Expected Output
Output using font size x-small and PGF backend rendered with pdflatex:
can you post the code you used to generate these? Since you are mixing the native Matplotlib fontsize declarations with LaTex, it might not lead to correct results.
Thank you for the hint! Sorry, I didn't have time to create a simple MWE. I've tried setting the font sizes explicitly in pt, and that solved the problem. I thought internally, smallx-small etc. would translate to LaTex's \small{} and \footnotesize{} font sizes which would be a nice feature. As for now, you would have to set all desired font sizes in pt manually.
My guess is, the LaTex font you are using only allows certain quantized font sizes. This might result in the same quantized fontsize corresponding to both 'small', 'x-small' scalings (I am not 100% sure if this is the correct explanation).
I think you are right. So I guess, the only way for now to accomplish consistent font sizes to use within a LaTex document is to specify all the font sizes in pt directly. This is a little cumbersome but probably not a problem of Matplotlib but rather a task for an extra package.
But how would I specify that in Matplotlib? I have tried setting the fontsizes in the .rc file to \footnotesize{} etc. but the syntax does not work and I don't see anything in the font manger that points towards such an option.
Here is a small example showing how to control font size when you are using LaTex with Matplotlib.
If this answers your question, please feel free to close this issue.
Ah yes I see what you mean. This, to be honest, seems to be even more cumbersome then putting in the correct font sizes in pt in the rc or style file.
Regarding the issue: I still feel like this could be better documented in the LaTex guide of Matplotlib, as one of the goals of Matplotlib is to create publish ready plots. If you don't feel like, this is a Matplotlib issue, I don't have a problem with closing it.
I will take this up over the weekend and try to document this (in addition to #11586 related to the use of TeX. I did start a PR #11718 but couldn't follow through).
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
I think this is actually caused by the "optical sizes" of a font (sometimes found in OpenType variable fonts). When you zoom in on certain small pt sized fonts, they will look distorted, but from the normal intended zoom level it is more appealing to the human eye. This is tricky to track down due to the subtlety, but once you know what to look for, it's easy to find resources explaining it (e.g. link, link, link, link).
Sorry for bumping a 5+ year old issue. I figured this would be helpful for people that stumble across this issue in the future (like myself), to know that it's a feature and not a bug in matplotlib or LaTeX.
Activity
pharshalp commentedon Sep 7, 2018
can you post the code you used to generate these? Since you are mixing the native Matplotlib fontsize declarations with LaTex, it might not lead to correct results.
MaxSchambach commentedon Sep 7, 2018
Thank you for the hint! Sorry, I didn't have time to create a simple MWE. I've tried setting the font sizes explicitly in pt, and that solved the problem. I thought internally,
smallx-smalletc. would translate to LaTex's\small{}and\footnotesize{}font sizes which would be a nice feature. As for now, you would have to set all desired font sizes in pt manually.pharshalp commentedon Sep 8, 2018
If you look at https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/font_manager.py it shows the following scaling values...
My guess is, the LaTex font you are using only allows certain quantized font sizes. This might result in the same quantized fontsize corresponding to both 'small', 'x-small' scalings (I am not 100% sure if this is the correct explanation).
MaxSchambach commentedon Sep 10, 2018
I think you are right. So I guess, the only way for now to accomplish consistent font sizes to use within a LaTex document is to specify all the font sizes in pt directly. This is a little cumbersome but probably not a problem of Matplotlib but rather a task for an extra package.
pharshalp commentedon Sep 10, 2018
or you could use relative sizes i.e. \small{}, \large{} etc
MaxSchambach commentedon Sep 10, 2018
But how would I specify that in Matplotlib? I have tried setting the fontsizes in the .rc file to
\footnotesize{}etc. but the syntax does not work and I don't see anything in the font manger that points towards such an option.pharshalp commentedon Sep 10, 2018
Here is a small example showing how to control font size when you are using LaTex with Matplotlib.
If this answers your question, please feel free to close this issue.
MaxSchambach commentedon Sep 11, 2018
Ah yes I see what you mean. This, to be honest, seems to be even more cumbersome then putting in the correct font sizes in pt in the rc or style file.
Regarding the issue: I still feel like this could be better documented in the LaTex guide of Matplotlib, as one of the goals of Matplotlib is to create publish ready plots. If you don't feel like, this is a Matplotlib issue, I don't have a problem with closing it.
jklymak commentedon Sep 11, 2018
Fixes to documentation or code most welcome. It does seem that xsmall and xxsmall should give different font sizes.
pharshalp commentedon Sep 18, 2018
I will take this up over the weekend and try to document this (in addition to #11586 related to the use of TeX. I did start a PR #11718 but couldn't follow through).
github-actions commentedon May 16, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
voidstarstar commentedon May 14, 2024
I think this is actually caused by the "optical sizes" of a font (sometimes found in OpenType variable fonts). When you zoom in on certain small pt sized fonts, they will look distorted, but from the normal intended zoom level it is more appealing to the human eye. This is tricky to track down due to the subtlety, but once you know what to look for, it's easy to find resources explaining it (e.g. link, link, link, link).
Sorry for bumping a 5+ year old issue. I figured this would be helpful for people that stumble across this issue in the future (like myself), to know that it's a feature and not a bug in matplotlib or LaTeX.