Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 83f03e6

Browse filesBrowse files
meeseeksmachinetimhoffm
authored andcommitted
Backport PR #12572: Fix singleton hist labels (#12594)
1 parent 3de5f14 commit 83f03e6
Copy full SHA for 83f03e6

File tree

Expand file treeCollapse file tree

2 files changed

+17
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-0
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6759,6 +6759,8 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
67596759
labels = [None]
67606760
elif isinstance(label, str):
67616761
labels = [label]
6762+
elif not np.iterable(label):
6763+
labels = [str(label)]
67626764
else:
67636765
labels = [str(lab) for lab in label]
67646766

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,6 +3065,21 @@ def test_hist_emptydata():
30653065
ax.hist([[], range(10), range(10)], histtype="step")
30663066

30673067

3068+
def test_hist_labels():
3069+
# test singleton labels OK
3070+
fig, ax = plt.subplots()
3071+
l = ax.hist([0, 1], label=0)
3072+
assert l[2][0].get_label() == '0'
3073+
l = ax.hist([0, 1], label=[0])
3074+
assert l[2][0].get_label() == '0'
3075+
l = ax.hist([0, 1], label=None)
3076+
assert l[2][0].get_label() == '_nolegend_'
3077+
l = ax.hist([0, 1], label='0')
3078+
assert l[2][0].get_label() == '0'
3079+
l = ax.hist([0, 1], label='00')
3080+
assert l[2][0].get_label() == '00'
3081+
3082+
30683083
@image_comparison(baseline_images=['transparent_markers'], remove_text=True)
30693084
def test_transparent_markers():
30703085
np.random.seed(0)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.