Skip to content

Commit 87aa310

Browse files
authored
Merge pull request #12572 from jklymak/fix-singleton-hist-labels
Fix singleton hist labels
2 parents 6045296 + f38b1c9 commit 87aa310

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6758,6 +6758,8 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
67586758
labels = [None]
67596759
elif isinstance(label, str):
67606760
labels = [label]
6761+
elif not np.iterable(label):
6762+
labels = [str(label)]
67616763
else:
67626764
labels = [str(lab) for lab in label]
67636765

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,6 +3073,21 @@ def test_hist_emptydata():
30733073
ax.hist([[], range(10), range(10)], histtype="step")
30743074

30753075

3076+
def test_hist_labels():
3077+
# test singleton labels OK
3078+
fig, ax = plt.subplots()
3079+
l = ax.hist([0, 1], label=0)
3080+
assert l[2][0].get_label() == '0'
3081+
l = ax.hist([0, 1], label=[0])
3082+
assert l[2][0].get_label() == '0'
3083+
l = ax.hist([0, 1], label=None)
3084+
assert l[2][0].get_label() == '_nolegend_'
3085+
l = ax.hist([0, 1], label='0')
3086+
assert l[2][0].get_label() == '0'
3087+
l = ax.hist([0, 1], label='00')
3088+
assert l[2][0].get_label() == '00'
3089+
3090+
30763091
@image_comparison(baseline_images=['transparent_markers'], remove_text=True)
30773092
def test_transparent_markers():
30783093
np.random.seed(0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy