-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix Text
class bug when font
argument is provided without math_fontfamily
#20101
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
Conversation
@diegopetrola may take a glance of it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping @matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
I notice that another issue still exists after the initial fix, since the argument order matters. import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['mathtext.fontset'] = 'cm'
plt.figure(figsize=(6, 5))
plt.plot(range(11), color="0.9")
msg = (r"Normal Text. $Text\ in\ math\ mode:\ "
r"\int_{0}^{\infty } x^2 dx$")
plt.text(1, 7, msg, size=12, math_fontfamily='dejavusans', font='Arial')
plt.show() If we put matplotlib/lib/matplotlib/artist.py Lines 1059 to 1064 in 4e10777
where in L1048 for k, v in props.items(): the traverse order follows the passing argument orders.
Therefore, we must ensure |
This won't happen if you pass matplotlib/lib/matplotlib/text.py Lines 177 to 181 in 54a4b6f
But I think these 2 different names just equivalent aliases. So A possible solution is to treat font together with fontproperties as well.
|
A better fix might be using matplotlib/lib/matplotlib/text.py Lines 106 to 119 in 54a4b6f
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please give your PRs more descriptive titles.
This could also do with a test.
indent fix Co-authored-by: Elliott Sales de Andrade <[email protected]>
Text
class when font
argument is provided without math_fontfamily
Text
class when font
argument is provided without math_fontfamily
Text
class bug when font
argument is provided without math_fontfamily
The test functions have been commited. @QuLogic |
Please remove the “need tests” tag, since now it need review. |
@QuLogic Have fixed. Sorry for my carelessness. |
This will need a rebase for the conflicts, and the tests need to pass. |
Downstream CI seems to think this is not mergeable, though GitHub doesn't seem to be showing any conflicts. I guess this would need a rebase to work properly. |
Sorry for first time dealing with co-operation workflow on GitHub. I create a pull request to merge master commits to my PR and solve the merge conflict by myself, guess it is equivalent to rebase all master commits onto my branch. Ping me if anything is wrong. |
Oops, I only meant to Approve the workflows (that is very annoying to have to re-do so much), not mark the PR as ready. Is it ready? |
@QuLogic I think it's ready. I'm fine if it requires more reviewer. |
Thanks @ain-soph! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again. |
…ontfamily` (matplotlib#20101) * fix mathtext.fontset issue * fix argument order issue * better fix using alias_map * indent fix * Update lib/matplotlib/text.py indent fix Co-authored-by: Elliott Sales de Andrade <[email protected]> * add test * split into 2 test methods * fix test * add a whitespace * use cbook.normalize_kwargs * no need to copy (normalize_kwargs already copy it) Co-authored-by: Elliott Sales de Andrade <[email protected]>
PR Summary
Fix bug of #20099
Issue Analysis
When you pass
font='Arial'
toplt.text()
withoutmath_fontfamily='cm'
(Arial
andcm
just for example), it will raise Exception.It is expected that the
math_fontfamily
will use the global default valuercParams['mathtext.fontset']
. However, it isNone
actually.The reason is that in
matplotlib/lib/matplotlib/text.py
Line 171 in 54a4b6f
font='Arial'
is passed in kwargs, passing tomatplotlib/lib/matplotlib/artist.py
Lines 1059 to 1064 in 54a4b6f
go to
Text.set_font_properties
and thenmatplotlib/lib/matplotlib/font_manager.py
Line 689 in 54a4b6f
Finally it calls
Text(font)
, goes into the if conditionmatplotlib/lib/matplotlib/font_manager.py
Lines 653 to 659 in 54a4b6f
It returns without
self.set_math_fontfamily(math_fontfamily)
(since it only occurs when if condition is False), leading tomath_fontfamily=None
rather than the global default.