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

Skip to content

Backport PR #20225 on branch v3.4.x (FIX: correctly handle ax.legend(..., legendcolor='none')) #20234

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ def __init__(self, parent, handles, labels,
break
except AttributeError:
pass
elif isinstance(labelcolor, str) and labelcolor == 'none':
for text in self.texts:
text.set_color(labelcolor)
elif np.iterable(labelcolor):
for text, color in zip(self.texts,
itertools.cycle(
Expand Down
7 changes: 4 additions & 3 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,16 +552,17 @@ def test_legend_title_fontsize():
assert leg.get_title().get_fontsize() == 22


def test_legend_labelcolor_single():
@pytest.mark.parametrize('color', ('red', 'none', (.5, .5, .5)))
def test_legend_labelcolor_single(color):
# test labelcolor for a single color
fig, ax = plt.subplots()
ax.plot(np.arange(10), np.arange(10)*1, label='#1')
ax.plot(np.arange(10), np.arange(10)*2, label='#2')
ax.plot(np.arange(10), np.arange(10)*3, label='#3')

leg = ax.legend(labelcolor='red')
leg = ax.legend(labelcolor=color)
for text in leg.get_texts():
assert mpl.colors.same_color(text.get_color(), 'red')
assert mpl.colors.same_color(text.get_color(), color)


def test_legend_labelcolor_list():
Expand Down