Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 6 commits into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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 ?

Copy link
Contributor Author

@s0vereign s0vereign Aug 9, 2017

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:

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

shadow : None or bool
?

Copy link
Member

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.

# explicitly passed. See Issue 8943
if framealpha is None:
self.get_frame().set_alpha(rcParams["legend.framealpha"])
if shadow is True:
self.framealpha = 1
else:
self.get_frame().set_alpha(rcParams["legend.framealpha"])
Copy link
Member

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.

Copy link
Contributor Author

@s0vereign s0vereign Aug 4, 2017

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.

else:
self.get_frame().set_alpha(framealpha)

Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,12 @@ def test_handler_numpoints():
fig, ax = plt.subplots()
ax.plot(range(5), label='test')
ax.legend(numpoints=0.5)


def test_shadow_framealpha():
# Test if framealpha is activated when shadow is True
# and framealpha is not explicitly passed'''
fig, ax = plt.subplots()
ax.plot(range(100), label="test")
leg = ax.legend(shadow=True, facecolor='w')
assert leg.framealpha == 1