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

Backport PR #12572 on branch v3.0.x (Fix singleton hist labels) #12594

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
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
2 changes: 2 additions & 0 deletions 2 lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6759,6 +6759,8 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
labels = [None]
elif isinstance(label, str):
labels = [label]
elif not np.iterable(label):
labels = [str(label)]
else:
labels = [str(lab) for lab in label]

Expand Down
15 changes: 15 additions & 0 deletions 15 lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3065,6 +3065,21 @@ def test_hist_emptydata():
ax.hist([[], range(10), range(10)], histtype="step")


def test_hist_labels():
# test singleton labels OK
fig, ax = plt.subplots()
l = ax.hist([0, 1], label=0)
assert l[2][0].get_label() == '0'
l = ax.hist([0, 1], label=[0])
assert l[2][0].get_label() == '0'
l = ax.hist([0, 1], label=None)
assert l[2][0].get_label() == '_nolegend_'
l = ax.hist([0, 1], label='0')
assert l[2][0].get_label() == '0'
l = ax.hist([0, 1], label='00')
assert l[2][0].get_label() == '00'


@image_comparison(baseline_images=['transparent_markers'], remove_text=True)
def test_transparent_markers():
np.random.seed(0)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.