-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fixed a bug where rcParams settings were being ignored for formatting axes labels #25237
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -8431,3 +8431,15 @@ def test_zorder_and_explicit_rasterization(): | |||||||
ln, = ax.plot(range(5), rasterized=True, zorder=1) | ||||||||
with io.BytesIO() as b: | ||||||||
8000 fig.savefig(b, format='pdf') | ||||||||
|
||||||||
|
||||||||
@mpl.style.context('default') | ||||||||
def test_rc_axes_label_formatting(): | ||||||||
mpl.rcParams['axes.labelcolor'] = 'red' | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think these should be wrapped in an rcContext, otherwise they apply for the rest of the test file, which could be confusing for future tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it should be fine because the matplotlib/lib/matplotlib/style/core.py Line 220 in f726d2c
Admittedly, I have not tested it. |
||||||||
mpl.rcParams['axes.labelsize'] = 20 | ||||||||
mpl.rcParams['axes.labelweight'] = 'bold' | ||||||||
|
||||||||
ax = plt.axes() | ||||||||
assert ax.xaxis.label.get_color() == 'red' | ||||||||
assert ax.xaxis.label.get_fontsize() == 20 | ||||||||
assert ax.xaxis.label.get_fontweight() == 'bold' |
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.
Shouldn't this all happen in
_reset_visual_defaults
?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.
self.label
is simply aText
instance, soself.label._reset_visual_defaults()
looks, for example, at thetext.color
rcParams instead of theaxes.labelcolor
rcParams.self.label._reset_visual_defaults()
does accept input arguments to override text defaults (although arguably that that doesn't make complete sense given the name of the method). So, for color in specific, one could callself.label._reset_visual_defaults(color=mpl.rcParams['axes.labelcolor'])
. Foraxes.labelsize
andaxes.labelweight
, it takes a little more effort because those have to be passed in through thefontproperties
keyword argument.Ultimately, I decided that it was overly complicated to pass in those arguments to
_reset_visual_defaults()
or to modify that method forself.label
to be aware of the defaults for an axis label rather than the defaults for text. The approach that I took in this PR felt more straightforward.I have added a clarifying comment for future maintainers.