@@ -6528,18 +6528,16 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
6528
6528
6529
6529
for xi , wi in zip (x , w ):
6530
6530
if wi is not None and len (wi ) != len (xi ):
6531
- raise ValueError (
6532
- 'weights should have the same shape as x' )
6531
+ raise ValueError ('weights should have the same shape as x' )
6533
6532
6534
6533
if color is None :
6535
6534
color = [self ._get_lines .get_next_color () for i in range (nx )]
6536
6535
else :
6537
6536
color = mcolors .to_rgba_array (color )
6538
6537
if len (color ) != nx :
6539
- error_message = (
6540
- "color kwarg must have one color per data set. %d data "
6541
- "sets and %d colors were provided" % (nx , len (color )))
6542
- raise ValueError (error_message )
6538
+ raise ValueError (f"The 'color' keyword argument must have one "
6539
+ f"color per dataset, but { nx } datasets and "
6540
+ f"{ len (color )} colors were provided" )
6543
6541
6544
6542
hist_kwargs = dict ()
6545
6543
@@ -6555,9 +6553,7 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
6555
6553
# np.minnan returns nan for all nan input
6556
6554
xmin = min (xmin , np .nanmin (xi ))
6557
6555
xmax = max (xmax , np .nanmax (xi ))
6558
- # make sure we have seen at least one non-nan and finite
6559
- # value before we reset the bin range
6560
- if not np .isnan ([xmin , xmax ]).any () and not (xmin > xmax ):
6556
+ if xmin <= xmax : # Only happens if we have seen a finite value.
6561
6557
bin_range = (xmin , xmax )
6562
6558
6563
6559
# If bins are not specified either explicitly or via range,
@@ -6667,9 +6663,9 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
6667
6663
x [2 * len (bins )- 1 :] = x [1 :2 * len (bins )- 1 ][::- 1 ]
6668
6664
6669
6665
if bottom is None :
6670
- bottom = np . zeros ( len ( bins ) - 1 )
6666
+ bottom = 0
6671
6667
6672
- y [1 :2 * len (bins )- 1 :2 ], y [2 :2 * len (bins ):2 ] = bottom , bottom
6668
+ y [1 :2 * len (bins )- 1 :2 ] = y [2 :2 * len (bins ):2 ] = bottom
6673
6669
y [2 * len (bins )- 1 :] = y [1 :2 * len (bins )- 1 ][::- 1 ]
6674
6670
6675
6671
if log :
@@ -6693,8 +6689,7 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
6693
6689
# top of the previous polygon becomes the bottom
6694
6690
y [2 * len (bins )- 1 :] = y [1 :2 * len (bins )- 1 ][::- 1 ]
6695
6691
# set the top of this polygon
6696
- y [1 :2 * len (bins )- 1 :2 ], y [2 :2 * len (bins ):2 ] = (m + bottom ,
6697
- m + bottom )
6692
+ y [1 :2 * len (bins )- 1 :2 ] = y [2 :2 * len (bins ):2 ] = m + bottom
6698
6693
6699
6694
# The starting point of the polygon has not yet been
6700
6695
# updated. So far only the endpoint was adjusted. This
@@ -6735,22 +6730,15 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
6735
6730
self .set_autoscaley_on (_saved_autoscaley )
6736
6731
self ._request_autoscale_view ()
6737
6732
6738
- if label is None :
6739
- labels = [None ]
6740
- elif isinstance (label , str ):
6741
- labels = [label ]
6742
- elif not np .iterable (label ):
6743
- labels = [str (label )]
6744
- else :
6745
- labels = [str (lab ) for lab in label ]
6746
-
6733
+ # If None, make all labels None (via zip_longest below); otherwise,
6734
+ # cast each element to str, but keep a single str as it.
6735
+ labels = [] if label is None else np .atleast_1d (np .asarray (label , str ))
6747
6736
for patch , lbl in itertools .zip_longest (patches , labels ):
6748
6737
if patch :
6749
6738
p = patch [0 ]
6750
6739
p .update (kwargs )
6751
6740
if lbl is not None :
6752
6741
p .set_label (lbl )
6753
-
6754
6742
for p in patch [1 :]:
6755
6743
p .update (kwargs )
6756
6744
p .set_label ('_nolegend_' )
0 commit comments