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

Skip to content

Commit c50a374

Browse files
authored
Merge pull request #20225 from tacaswell/fix_legend_labelcolor_none
FIX: correctly handle ax.legend(..., legendcolor='none')
2 parents 136dc16 + 4b70c41 commit c50a374

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/matplotlib/legend.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ def __init__(self, parent, handles, labels,
550550
break
551551
except AttributeError:
552552
pass
553+
elif isinstance(labelcolor, str) and labelcolor == 'none':
554+
for text in self.texts:
555+
text.set_color(labelcolor)
553556
elif np.iterable(labelcolor):
554557
for text, color in zip(self.texts,
555558
itertools.cycle(

lib/matplotlib/tests/test_legend.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,16 +583,17 @@ def test_legend_title_fontprop_fontsize():
583583
assert leg5.get_title().get_fontsize() == 20
584584

585585

586-
def test_legend_labelcolor_single():
586+
@pytest.mark.parametrize('color', ('red', 'none', (.5, .5, .5)))
587+
def test_legend_labelcolor_single(color):
587588
# test labelcolor for a single color
588589
fig, ax = plt.subplots()
589590
ax.plot(np.arange(10), np.arange(10)*1, label='#1')
590591
ax.plot(np.arange(10), np.arange(10)*2, label='#2')
591592
ax.plot(np.arange(10), np.arange(10)*3, label='#3')
592593

593-
leg = ax.legend(labelcolor='red')
594+
leg = ax.legend(labelcolor=color)
594595
for text in leg.get_texts():
595-
assert mpl.colors.same_color(text.get_color(), 'red')
596+
assert mpl.colors.same_color(text.get_color(), color)
596597

597598

598599
def test_legend_labelcolor_list():

0 commit comments

Comments
 (0)