-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
If Legend shadow=True set framealpha=1 if not passed explicitly instead of consulting rcParams #8988
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
lib/matplotlib/legend.py
Outdated
if shadow is True: | ||
self.framealpha = 1 | ||
else: | ||
self.get_frame().set_alpha(rcParams["legend.framealpha"]) |
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.
why are there two ways of setting framealpha? I would stick with the self.get_frame().set_alpha()
way, unless we should change it everywhere to self.framealpha
. Also, we don't need shadow is True
, it can be just shadow
.
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.
Alright will change both lines as proposed.
the test to use the get_alpha method
fig, ax = plt.subplots() | ||
ax.plot(range(100), label="test") | ||
leg = ax.legend(shadow=True, facecolor='w') | ||
assert leg.get_frame().get_alpha() == 1 |
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 will need a new (empty) line at the end to assuage pep8
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.
π for the code.
This case of ignoring the default facealpha needs to be documented in Axes.legend
.
Thanks for you work on this!
@@ -384,8 +384,13 @@ def __init__(self, parent, handles, labels, | |||
# init with null renderer | |||
self._init_legend_box(handles, labels, markerfirst) | |||
|
|||
# If shadow is activated use framealpha if not |
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 comment is perfect here! Can you also add a note about this to the docstring at https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_axes.py#L298 ?
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.
Always glad to help. π
I would put it into the doc of framealpha:
matplotlib/lib/matplotlib/axes/_axes.py
Line 427 in 5a24121
framealpha : None or float |
to make clear that if shadow is activated and framealpha is
None
it will set the value to be 1 instead of taking it from legend.framealpha
:data:rcParam<matplotlib.rcParams>
.
Should I also add something to
matplotlib/lib/matplotlib/axes/_axes.py
Line 422 in 5a24121
shadow : None or bool |
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.
To both? The goal is to make sure users are not confused / can un-confuse them selves easily. Putting it in shadow
warns someone using it that it might affect other parts and someone who is having issues with the default framalpha
being ignored might go check it's docstring.
for ignoring framealpha default value if shadow is activated.
@tacaswell did you have a look over the recent changes? |
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.
π LGTM
Thank @s0vereign and congratulations on your first Matplotlib PR π Hopefully we will hear from you again! |
Will be looking for issues I can fix and get more familiar with the code π |
PR Summary
This PR fixes a behavior in the legend, that if shadow is set
True
the legend will be grayed out.
The changes are in detail:
so that not the rcParams are not consulted if shadow is set
to True and framealpha was not passed.
The following code:
results in:

The PR fixes Issue #8943 according to @tacaswell instructions.
PR Checklist