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

Skip to content

Commit 9a4260a

Browse files
authored
Merge pull request #26828 from meeseeksmachine/auto-backport-of-pr-26825-on-v3.8.x
Backport PR #26825 on branch v3.8.x (Fix issue with non-string labels and legend)
2 parents 3c12de0 + 9897576 commit 9a4260a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/matplotlib/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __new__(cls, *args, **kwargs):
1919
def __init__(self, kl, label=None):
2020
self._callbacks = cbook.CallbackRegistry(signals=["pchanged"])
2121
self._remove_method = None
22-
self._label = label
22+
self._label = str(label) if label is not None else None
2323

2424
def remove(self):
2525
for c in cbook.flatten(

lib/matplotlib/tests/test_container.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import matplotlib.pyplot as plt
23

34

@@ -28,3 +29,9 @@ def test_errorbar_remove():
2829

2930
eb = ax.errorbar([1], [1], fmt='none')
3031
eb.remove()
32+
33+
34+
def test_nonstring_label():
35+
# Test for #26824
36+
plt.bar(np.arange(10), np.random.rand(10), label=1)
37+
plt.legend()

0 commit comments

Comments
 (0)