Skip to content

Commit dc425b0

Browse files
committed
revert to original behaviour of having black legend labels for invisible handles; can pass empty string " " to achieve empty/invisible label instead; having a black legend label by default allows the creation of neutrally coloured dummy entries
1 parent 64e3a86 commit dc425b0

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

lib/matplotlib/legend.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,6 @@ def __init__(
618618
break
619619
except AttributeError:
620620
continue
621-
else:
622-
text.set_color('none')
623621
elif cbook._str_equal(labelcolor, 'none'):
624622
for text in self.texts:
625623
text.set_color(labelcolor)

lib/matplotlib/tests/test_legend.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,16 +1240,11 @@ def test_legend_labelcolor_linecolor_plot():
12401240
assert mpl.colors.same_color(tc, p[0].get_markerfacecolor())
12411241

12421242
fig, ax = plt.subplots()
1243-
p = ax.plot(x, 'o', c='none', mec='none', label="invisible circles and label")
1243+
p = ax.plot(x, 'o', c='none', mec='none',
1244+
label="black label despite invisible circles for dummy entries")
12441245
leg = ax.legend(labelcolor='linecolor')
12451246
tc = leg.texts[0].get_color()
1246-
assert mpl.colors.same_color(tc, 'none')
1247-
assert mpl.colors.same_color(tc, leg.get_lines()[0].get_markerfacecolor())
1248-
assert mpl.colors.same_color(tc, leg.get_lines()[0].get_markeredgecolor())
1249-
assert mpl.colors.same_color(tc, leg.get_lines()[0].get_color())
1250-
assert mpl.colors.same_color(tc, p[0].get_markerfacecolor())
1251-
assert mpl.colors.same_color(tc, p[0].get_markeredgecolor())
1252-
assert mpl.colors.same_color(tc, p[0].get_color())
1247+
assert mpl.colors.same_color(tc, 'k')
12531248
plt.close('all')
12541249

12551250

@@ -1299,10 +1294,11 @@ def test_legend_labelcolor_linecolor_scatter():
12991294
assert mpl.colors.same_color(tc, p.get_facecolor())
13001295

13011296
fig, ax = plt.subplots()
1302-
p = ax.scatter(x, x, c='none', ec='none', label="invisible circles and label")
1297+
p = ax.scatter(x, x, c='none', ec='none',
1298+
label="black label despite invisible circles for dummy entries")
13031299
leg = ax.legend(labelcolor='linecolor')
13041300
tc = leg.texts[0].get_color()
1305-
assert mpl.colors.same_color(tc, 'none')
1301+
assert mpl.colors.same_color(tc, 'k')
13061302
plt.close('all')
13071303

13081304

0 commit comments

Comments
 (0)