From 5258ec0aca79065d01cfe1a105746d65e6f59cfa Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 19 Oct 2018 16:19:50 -0700 Subject: [PATCH 1/2] FIX: allow singleton labels in hist --- lib/matplotlib/axes/_axes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 8b737e564f77..c2230d3b44a4 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6758,6 +6758,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] From f38b1c9f851f075d587d394094851d005c6dfe98 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 19 Oct 2018 16:24:59 -0700 Subject: [PATCH 2/2] TST: test for hist labels allowing singletons --- lib/matplotlib/tests/test_axes.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 8efe0b11786c..49e0a9826c4c 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3073,6 +3073,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