From 5be31376b70450f07fb83ebeabaff97099a1072a Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 22 Oct 2018 18:25:16 +0100 Subject: [PATCH] Backport PR #12572: Fix singleton hist labels --- lib/matplotlib/axes/_axes.py | 2 ++ lib/matplotlib/tests/test_axes.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index e90c119657cd..2065871157dd 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -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] diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 17eb624c7143..3c9b7dfc56d9 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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) 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