-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
8000
[Bug]: PGF font size mismatch between measurement and output #26892
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
Milestone
Comments
2 tasks
Socob
pushed a commit
to Socob/matplotlib
that referenced
this issue
Oct 3, 2023
Socob
added a commit
to Socob/matplotlib
that referenced
this issue
Oct 3, 2023
Socob
added a commit
to Socob/matplotlib
that referenced
this issue
Oct 3, 2023
Socob
added a commit
to Socob/matplotlib
that referenced
this issue
Oct 3, 2023
Socob
added a commit
to Socob/matplotlib
that referenced
this issue
Oct 3, 2023
Thank you for the workaround. I had a related problem: What constantly happens because of that is also that the legend boxes were systematically too big compared to the inner text. Usually, that is not a problem, but when the text is too long, this is more of an issue. |
This was referenced Apr 22, 2024
Closed
Socob
added a commit
to Socob/matplotlib
that referenced
this issue
Apr 22, 2024
Socob
added a commit
to Socob/matplotlib
that referenced
this issue
Apr 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Bug summary
When using the PGF backend, different LaTeX document font size settings are used when measuring widths vs. producing output. Although this is usually not a problem (since all text produced by the PGF backend locally sets the font properties), packages used in the custom preamble (such as
unicode-math
) may depend on the font size settings, leading to incorrect width measurements since different outcomes are produced in the two cases.Code for reproduction
Actual outcome
Math text has a different width (characters are comparatively wider when scaled to the same height) and thus exceeds the legend boundary (tick labels also have some slight spacing issues):
Expected outcome
Text should be within the legend boundary:
Additional information
The main issue causing the problem in my example is that different font sizes are passed to
\documentclass
in different cases:matplotlib/lib/matplotlib/backends/backend_pgf.py
Lines 186 to 188 in ff552f4
matplotlib/lib/matplotlib/backends/backend_pgf.py
Line 813 in ff552f4
matplotlib/lib/matplotlib/backends/backend_pgf.py
Line 923 in ff552f4
This specific issue is only present in matplotlib ≥ v3.6.0 and seems to be a historical accident carried over from when the document class was changed from
minimal
toarticle
in 4d85f70 (#23443).\documentclass{minimal}
actually ignores any options passed to it (including12pt
), so that option in the original code was spurious and there was no mismatch between the cases with and without this option. But when this was changed to\documentclass{article}
, the option12pt
did start taking effect, leading to the discrepancy.However, more generally, the code always had an implicit dependence on the LaTeX font size setting, which does affect things like the
unicode-math
package (which selects different versions of math fonts depending on the font size). So when saving as.pgf
and using these files directly in LaTeX documents, there is still the potential for problems to show up. Another consequence of this is that the standard LaTeX font size commands (\tiny
, …,\normalsize
, …,\Huge
) are also relative to this obscure font size setting (instead ofrcParams['font.size']
).Workaround for current releases: Manually set the font size in the preamble.
Operating system
No response
Matplotlib Version
3.8.0
Matplotlib Backend
pgf
Python version
No response
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: