Skip to content
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

FIX: Prevent set_alpha from changing color of legend patch #22009

Merged
merged 1 commit into from Dec 21, 2021

Conversation

StefRe
Copy link
Contributor

@StefRe StefRe commented Dec 19, 2021

of polycollection (e.g. from fill_between) by updating original edge and face color too.

Closes #21966

PR Summary

When updating the properties of the legend patch from the PolyCollection returned by fill_between, the HandlerPolyCollection failed to set the original edge and face colors so that when later setting the alpha of the patch, its color was set to the default C0.
This was fixed by updating the original edge and face colors too.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [n/a] New features are documented, with examples if plot related.
  • [n/a] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [n/a] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [n/a] Documentation is sphinx and numpydoc compliant (the docs should build without error).

of polycollection (e.g. from fill_between) by updating original
edge and face color too.
@tacaswell tacaswell added this to the v3.5.2 milestone Dec 20, 2021
@tacaswell
Copy link
Member

@StefRe Do you think there something reasonable thing to search on to see if we have any other moles of this category that need to be whacked?

@StefRe
Copy link
Contributor Author

StefRe commented Dec 20, 2021

@tacaswell
I tested all plot types and the custom legend types from the legend guide and they're all OK. So I'm pretty confident that there no more instances of this issue, but in the end this is just a subjective assessment, not a automatic code review.

@tacaswell
Copy link
Member

It is much easier to prove a bug exists than it does not exist ;) I was thinking of a heuristiic like "skimmed all of the functions called def _update_prop that exist in the code base and they all remember to copy the original colors", but testing that it works is better 👍🏻 . Thank you for the diligence.

@StefRe
Copy link
Contributor Author

StefRe commented Dec 20, 2021

@tacaswell a very rough heuristics would be looking around ...facecolor assignments and see if other ...facecolor properties (if they exist) are assigned too:

grep -r --include=*.py --exclude=test*.py -C5 -n 'facecolor = [a-zA-Z_][a-zA-Z0-9_\.]*facecolor' *.py | grep 'facecolor\|^\-'

which yields

collections.py:918:        self._original_facecolor = other._original_facecolor
collections.py-919-        self._facecolors = other._facecolors
--
legend_handler.py-789-        legend_handle._facecolor = first_color(orig_handle.get_facecolor())
legend_handler.py:791:        legend_handle._original_facecolor = orig_handle._original_facecolor
--
lines.py:1269:        self._markerfacecolor = other._markerfacecolor
lines.py-1270-        self._markerfacecoloralt = other._markerfacecoloralt
--
patches.py:257:        self._facecolor = other._facecolor
patches.py:259:        self._original_facecolor = other._original_facecolor

According to this, everything seems to be fine :).

@QuLogic QuLogic merged commit 95524e7 into matplotlib:main Dec 21, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Dec 21, 2021
@StefRe StefRe deleted the fix/issue21966 branch December 21, 2021 07:45
QuLogic added a commit that referenced this pull request Dec 21, 2021
…009-on-v3.5.x

Backport PR #22009 on branch v3.5.x (FIX: Prevent set_alpha from changing color of legend patch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Regression: Setting alpha on legend handle changes patch color
3 participants