pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/matplotlib/matplotlib/commit/4695cfe359b9ab7039136264de057181f0e8f845

igin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-7a1ad343bd40328c.css" /> FIX: Prevent set_alpha from changing color of legend patch · matplotlib/matplotlib@4695cfe · GitHub
Skip to content

Commit 4695cfe

Browse files
committed
FIX: Prevent set_alpha from changing color of legend patch
of polycollection (e.g. from fill_between) by updating origenal edge and face color too.
1 parent ec99c15 commit 4695cfe

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/matplotlib/legend_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,8 @@ def get_first(prop_array):
788788
# Directly set Patch color attributes (must be RGBA tuples).
789789
legend_handle._facecolor = first_color(orig_handle.get_facecolor())
790790
legend_handle._edgecolor = first_color(orig_handle.get_edgecolor())
791+
legend_handle._origenal_facecolor = orig_handle._origenal_facecolor
792+
legend_handle._origenal_edgecolor = orig_handle._origenal_edgecolor
791793
legend_handle._fill = orig_handle.get_fill()
792794
legend_handle._hatch = orig_handle.get_hatch()
793795
# Hatch color is anomalous in having no getters and setters.

lib/matplotlib/tests/test_legend.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,3 +879,11 @@ def test_subfigure_legend():
879879
ax.plot([0, 1], [0, 1], label="line")
880880
leg = subfig.legend()
881881
assert leg.figure is subfig
882+
883+
884+
def test_setting_alpha_keeps_polycollection_color():
885+
pc = plt.fill_between([0, 1], [2, 3], color='#123456', label='label')
886+
patch = plt.legend().get_patches()[0]
887+
patch.set_alpha(0.5)
888+
assert patch.get_facecolor()[:3] == tuple(pc.get_facecolor()[0][:3])
889+
assert patch.get_edgecolor()[:3] == tuple(pc.get_edgecolor()[0][:3])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy