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

Skip to content

Transparency not respected in legendPatch #3766

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

Closed
mrclary opened this issue Nov 8, 2014 · 4 comments
Closed

Transparency not respected in legendPatch #3766

mrclary opened this issue Nov 8, 2014 · 4 comments

Comments

@mrclary
Copy link

mrclary commented Nov 8, 2014

It seems after Matplotlib 1.3.1 (1.4.1, 1.4.2, not sure about 1.4.0) that setting the transparency of the facecolor or edgecolor properties of a legendPatch is not respected. Both properties can be changed together using legendPatch.set_alpha(...), but they cannot be set independently. Following is a MWE. Here, the legend's facecolor is changed, but the alpha specification (0.2) is ignored. A call to legendPatch.get_facecolor() confirms this.

import matplotlib.pyplot as plt

plt.plot(range(10))
leg = plt.legend(['Line'])
leg.legendPatch.set_facecolor([0.5,1,0.5,0.2])
@tacaswell tacaswell added this to the v1.4.3 milestone Nov 9, 2014
@tacaswell
Copy link
Member

I am a bit preplexed by this. It looks like the patch attached to the legend is a FancyBboxPatch which uses the set_facecolor method from Patch. The color is rgba-ified using colors.colorConverter.to_rgba(arg, self._alpha) which will ignore the alpha value passed in (the observed issue). However, looking at the blame for both of those functions, the only changes between 1.3.1 and 1.4 are from #3092 which should not have affected this.

@efiring
Copy link
Member

efiring commented Nov 9, 2014

853c26a
calls set_alpha() on the patch; once that is set, set_facecolor uses it to override the "a" in "rgba".

In other words, adding an rcParam changed _alpha of None to a default value; and once that is done, you are stuck with it until you explicitly change it! The painful saga of alpha-handling continues...

As a matter of style, the relevant bit of code in legend:

        if framealpha is None:
            self.get_frame().set_alpha(rcParams["legend.framealpha"])
        else:
            self.get_frame().set_alpha(framealpha)

is obfuscated by the use of the get_frame() method; what it gets is the legendPatch that was created in the same method a few lines above.

@mrclary
Copy link
Author

mrclary commented Nov 9, 2014

I've confirmed that the behavior exhibits after version 1.4.0 (1.3.1 and 1.4.0 are okay, >=1.4.1 not okay)

@tacaswell
Copy link
Member

I have a fix for this, just need to add some tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants