-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add legend.labelcolor in rcParams #20084
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
Add legend.labelcolor in rcParams #20084
Conversation
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.
64661db
to
2216de0
Compare
2216de0
to
9652ce5
Compare
9652ce5
to
5fbf7cf
Compare
Thanks for working on this! Overall 👍, but is it possible to have the default rcParam be None? Currently the default label color will fall back to the |
Sure. I think that making a little change in the lib/matplotlib/legend.py it can work. I will give it a try. |
5fbf7cf
to
2dabca5
Compare
7dc4eaa
to
a76663b
Compare
411cfac
to
942c3b2
Compare
lib/matplotlib/legend.py
Outdated
@@ -544,8 +544,11 @@ def __init__(self, parent, handles, labels, | |||
'mec': ['get_markeredgecolor', 'get_edgecolor'], | |||
} | |||
if labelcolor is None: | |||
pass | |||
elif isinstance(labelcolor, str) and labelcolor in color_getters: | |||
if mpl.rcParams['legend.labelcolor'] != 'none': |
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.
The legend docstring should note that this rcparam exists....
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.
Should this be `
if mpl.rcParams['legend.labelcolor'] != 'none': | |
if mpl.rcParams['legend.labelcolor'] is not None: |
along with similar changes to validator? There are a number of places where we use the string 'none'
as a color to mean "this thing does not get a color" and None
(the singleton) to mean "use the default color".
That said, currently doing
...
ax.legend(labelcolor='none')
does not result in an invisible label which is a bug in the implementation below (cycle of a 0 length thing is also 0 length, not infinite).
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.
The rcParam can't be able to both be None
and 'none'
, though, right? The fallback version would need a special value to work, like 'auto'
or 'textcolor'
?
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.
#20225 fixes the bug I noted above!
5fb07c8
to
8240661
Compare
@@ -179,6 +179,8 @@ def _update_bbox_to_anchor(self, loc_in_canvas): | |||
also be made to match the color of the line or marker using 'linecolor', | |||
'markerfacecolor' (or 'mfc'), or 'markeredgecolor' (or 'mec'). | |||
|
|||
Otherly, labelcolor can be set globally using :rc:`legend.labelcolor`. | |||
|
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.
Sorry to be picky, bit this should go in as
labelcolor : str or list, default: :rc:`legend.labelcolor`.
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.
Thanks for the review.
But when the rcParams[legend.labelcolor]
is None
(the default value(, should the docs say that it just uses the rcParams['text.color']
value?
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.
I think that should be specified in the description of the parameter if it is not already
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.
This is fine w/ me now. @tacaswell you have a block on this...
53bde8f
to
c905216
Compare
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.
Looks on the right path, but the default value should be None
not 'none'
.
lib/matplotlib/legend.py
Outdated
@@ -544,8 +544,11 @@ def __init__(self, parent, handles, labels, | |||
'mec': ['get_markeredgecolor', 'get_edgecolor'], | |||
} | |||
if labelcolor is None: | |||
pass | |||
elif isinstance(labelcolor, str) and labelcolor in color_getters: | |||
if mpl.rcParams['legend.labelcolor'] != 'none': |
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.
Should this be `
if mpl.rcParams['legend.labelcolor'] != 'none': | |
if mpl.rcParams['legend.labelcolor'] is not None: |
along with similar changes to validator? There are a number of places where we use the string 'none'
as a color to mean "this thing does not get a color" and None
(the singleton) to mean "use the default color".
That said, currently doing
...
ax.legend(labelcolor='none')
does not result in an invisible label which is a bug in the implementation below (cycle of a 0 length thing is also 0 length, not infinite).
c905216
to
ffbd8b9
Compare
49ac9a2
to
4397fa8
Compare
4397fa8
to
8354d0e
Compare
8354d0e
to
13149be
Compare
@tacaswell you are still blocking on this.... |
Thanks @Carloscerq ! Congratulations on your first merged Matplotlib PR 🎉 hope we hear from you again! |
PR Summary
This is a proposal for a new
legend
rcParam.The
legend.labelcolor
was proposed in #20049. It's for changing thelabelcolor
of all figures(similar to the labelcolor ofplt.legend
)Example:
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).