Skip to content
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 @@ -550,6 +550,9 @@ def __init__(self, parent, handles, labels,
break
except AttributeError:
pass
elif isinstance(labelcolor, str) and labelcolor == 'none':

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'd have thought these were redundant....

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a numpy array come is than elif obj == "none": gets us the "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" issue.

I thought about merging this with the conditional above, but was trying to avoid causing a rebase for @Carloscerq in #20084.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t worry about it. I think I can handle it over the weekend, and, if it’s the case, I can remake the #20084 .

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 @@ -583,16 +583,17 @@ def test_legend_title_fontprop_fontsize():
assert leg5.get_title().get_fontsize() == 20


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