Skip to content

Commit 335e76e

Browse files
committed
fix legends with labelcolor set to linecolor: change ordering from c, fc to mfc, fc, mec, ec, c; check if color is empty, none or transparent and loop on if so
1 parent dabaf62 commit 335e76e

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lib/matplotlib/legend.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,11 @@ def __init__(
576576
# set the text color
577577

578578
color_getters = { # getter function depends on line or patch
579-
'linecolor': ['get_color', 'get_facecolor'],
579+
'linecolor': ['get_markerfacecolor',
580+
'get_facecolor',
581+
'get_markeredgecolor',
582+
'get_edgecolor',
583+
'get_color'],
580584
'markerfacecolor': ['get_markerfacecolor', 'get_facecolor'],
581585
'mfc': ['get_markerfacecolor', 'get_facecolor'],
582586
'markeredgecolor': ['get_markeredgecolor', 'get_edgecolor'],
@@ -596,18 +600,27 @@ def __init__(
596600
try:
597601
color = getattr(handle, getter_name)()
598602
if isinstance(color, np.ndarray):
599-
if (
600-
color.shape[0] == 1
601-
or np.isclose(color, color[0]).all()
603+
if color.size == 0:
604+
continue
605+
elif (
606+
color.shape[0] == 1
607+
or np.isclose(color, color[0]).all()
602608
):
603609
text.set_color(color[0])
604610
else:
605611
pass
612+
elif isinstance(color, str) and str(color).lower() == 'none':
613+
continue
614+
elif (len(mpl.colors.to_rgba(color)) == 4
615+
and mpl.colors.to_rgba(color)[3] == 0):
616+
continue
606617
else:
607618
text.set_color(color)
608619
break
609620
except AttributeError:
610-
pass
621+
continue
622+
else:
623+
text.set_color('none')
611624
elif cbook._str_equal(labelcolor, 'none'):
612625
for text in self.texts:
613626
text.set_color(labelcolor)

0 commit comments

Comments
 (0)