@@ -8245,6 +8245,17 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8245
8245
if histtype == 'barstacked' and not stacked :
8246
8246
stacked = True
8247
8247
8248
+ # Check whether bins or range are given explicitly.
8249
+ binsgiven = (cbook .iterable (bins ) or bin_range is not None )
8250
+
8251
+ # basic input validation
8252
+ flat = np .ravel (x )
8253
+ if len (flat ) == 0 :
8254
+ raise ValueError ("x must have at least one data point" )
8255
+ elif len (flat ) == 1 and not binsgiven :
8256
+ raise ValueError (
8257
+ "x has only one data point. bins or range kwarg must be given" )
8258
+
8248
8259
# Massage 'x' for processing.
8249
8260
# NOTE: Be sure any changes here is also done below to 'weights'
8250
8261
if isinstance (x , np .ndarray ) or not iterable (x [0 ]):
@@ -8299,19 +8310,16 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8299
8310
# Save the datalimits for the same reason:
8300
8311
_saved_bounds = self .dataLim .bounds
8301
8312
8302
- # Check whether bins or range are given explicitly. In that
8303
- # case use those values for autoscaling.
8304
- binsgiven = (cbook .iterable (bins ) or bin_range is not None )
8305
-
8306
8313
# If bins are not specified either explicitly or via range,
8307
8314
# we need to figure out the range required for all datasets,
8308
8315
# and supply that to np.histogram.
8309
8316
if not binsgiven :
8310
8317
xmin = np .inf
8311
8318
xmax = - np .inf
8312
8319
for xi in x :
8313
- xmin = min (xmin , xi .min ())
8314
- xmax = max (xmax , xi .max ())
8320
+ if len (xi ) > 0 :
8321
+ xmin = min (xmin , xi .min ())
8322
+ xmax = max (xmax , xi .max ())
8315
8323
bin_range = (xmin , xmax )
8316
8324
8317
8325
#hist_kwargs = dict(range=range, normed=bool(normed))
@@ -8503,15 +8511,17 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8503
8511
xmin0 = max (_saved_bounds [0 ]* 0.9 , minimum )
8504
8512
xmax = self .dataLim .intervalx [1 ]
8505
8513
for m in n :
8506
- xmin = np .amin (m [m != 0 ]) # filter out the 0 height bins
8514
+ if np .sum (m ) > 0 : # make sure there are counts
8515
+ xmin = np .amin (m [m != 0 ]) # filter out the 0 height bins
8507
8516
xmin = max (xmin * 0.9 , minimum )
8508
8517
xmin = min (xmin0 , xmin )
8509
8518
self .dataLim .intervalx = (xmin , xmax )
8510
8519
elif orientation == 'vertical' :
8511
8520
ymin0 = max (_saved_bounds [1 ]* 0.9 , minimum )
8512
8521
ymax = self .dataLim .intervaly [1 ]
8513
8522
for m in n :
8514
- ymin = np .amin (m [m != 0 ]) # filter out the 0 height bins
8523
+ if np .sum (m ) > 0 : # make sure there are counts
8524
+ ymin = np .amin (m [m != 0 ]) # filter out the 0 height bins
8515
8525
ymin = max (ymin * 0.9 , minimum )
8516
8526
ymin = min (ymin0 , ymin )
8517
8527
self .dataLim .intervaly = (ymin , ymax )
0 commit comments