@@ -5169,6 +5169,17 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
51695169 if histtype == 'barstacked' and not stacked :
51705170 stacked = True
51715171
5172+ # Check whether bins or range are given explicitly.
5173+ binsgiven = (cbook .iterable (bins ) or bin_range is not None )
5174+
5175+ # basic input validation
5176+ flat = np .ravel (x )
5177+ if len (flat ) == 0 :
5178+ raise ValueError ("x must have at least one data point" )
5179+ elif len (flat ) == 1 and not binsgiven :
5180+ raise ValueError (
5181+ "x has only one data point. bins or range kwarg must be given" )
5182+
51725183 # Massage 'x' for processing.
51735184 # NOTE: Be sure any changes here is also done below to 'weights'
51745185 if isinstance (x , np .ndarray ) or not iterable (x [0 ]):
@@ -5223,19 +5234,16 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
52235234 # Save the datalimits for the same reason:
52245235 _saved_bounds = self .dataLim .bounds
52255236
5226- # Check whether bins or range are given explicitly. In that
5227- # case use those values for autoscaling.
5228- binsgiven = (cbook .iterable (bins ) or bin_range is not None )
5229-
52305237 # If bins are not specified either explicitly or via range,
52315238 # we need to figure out the range required for all datasets,
52325239 # and supply that to np.histogram.
52335240 if not binsgiven :
52345241 xmin = np .inf
52355242 xmax = - np .inf
52365243 for xi in x :
5237- xmin = min (xmin , xi .min ())
5238- xmax = max (xmax , xi .max ())
5244+ if len (xi ) > 0 :
5245+ xmin = min (xmin , xi .min ())
5246+ xmax = max (xmax , xi .max ())
52395247 bin_range = (xmin , xmax )
52405248
52415249 #hist_kwargs = dict(range=range, normed=bool(normed))
@@ -5430,15 +5438,17 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
54305438 xmin0 = max (_saved_bounds [0 ]* 0.9 , minimum )
54315439 xmax = self .dataLim .intervalx [1 ]
54325440 for m in n :
5433- xmin = np .amin (m [m != 0 ]) # filter out the 0 height bins
5441+ if np .sum (m ) > 0 : # make sure there are counts
5442+ xmin = np .amin (m [m != 0 ]) # filter out the 0 height bins
54345443 xmin = max (xmin * 0.9 , minimum )
54355444 xmin = min (xmin0 , xmin )
54365445 self .dataLim .intervalx = (xmin , xmax )
54375446 elif orientation == 'vertical' :
54385447 ymin0 = max (_saved_bounds [1 ]* 0.9 , minimum )
54395448 ymax = self .dataLim .intervaly [1 ]
54405449 for m in n :
5441- ymin = np .amin (m [m != 0 ]) # filter out the 0 height bins
5450+ if np .sum (m ) > 0 : # make sure there are counts
5451+ ymin = np .amin (m [m != 0 ]) # filter out the 0 height bins
54425452 ymin = max (ymin * 0.9 , minimum )
54435453 ymin = min (ymin0 , ymin )
54445454 self .dataLim .intervaly = (ymin , ymax )
0 commit comments