@@ -3886,10 +3886,9 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
3886
3886
if extent is not None :
3887
3887
xmin , xmax , ymin , ymax = extent
3888
3888
else :
3889
- xmin = np .amin (x )
3890
- xmax = np .amax (x )
3891
- ymin = np .amin (y )
3892
- ymax = np .amax (y )
3889
+ xmin , xmax = (np .amin (x ), np .amax (x )) if len (x ) else (0 , 1 )
3890
+ ymin , ymax = (np .amin (y ), np .amax (y )) if len (y ) else (0 , 1 )
3891
+
3893
3892
# to avoid issues with singular data, expand the min/max pairs
3894
3893
xmin , xmax = mtrans .nonsingular (xmin , xmax , expander = 0.1 )
3895
3894
ymin , ymax = mtrans .nonsingular (ymin , ymax , expander = 0.1 )
@@ -5652,12 +5651,14 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
5652
5651
5653
5652
# basic input validation
5654
5653
flat = np .ravel (x )
5655
- if len ( flat ) == 0 :
5656
- raise ValueError ( "x must have at least one data point" )
5654
+
5655
+ input_empty = len ( flat ) == 0
5657
5656
5658
5657
# Massage 'x' for processing.
5659
5658
# NOTE: Be sure any changes here is also done below to 'weights'
5660
- if isinstance (x , np .ndarray ) or not iterable (x [0 ]):
5659
+ if input_empty :
5660
+ x = np .array ([[]])
5661
+ elif isinstance (x , np .ndarray ) or not iterable (x [0 ]):
5661
5662
# TODO: support masked arrays;
5662
5663
x = np .asarray (x )
5663
5664
if x .ndim == 2 :
@@ -5712,7 +5713,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
5712
5713
# If bins are not specified either explicitly or via range,
5713
5714
# we need to figure out the range required for all datasets,
5714
5715
# and supply that to np.histogram.
5715
- if not binsgiven :
5716
+ if not binsgiven and not input_empty :
5716
5717
xmin = np .inf
5717
5718
xmax = - np .inf
5718
5719
for xi in x :
@@ -5917,17 +5918,18 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
5917
5918
if np .sum (m ) > 0 : # make sure there are counts
5918
5919
xmin = np .amin (m [m != 0 ])
5919
5920
# filter out the 0 height bins
5920
- xmin = max (xmin * 0.9 , minimum )
5921
+ xmin = max (xmin * 0.9 , minimum ) if not input_empty else minimum
5921
5922
xmin = min (xmin0 , xmin )
5922
5923
self .dataLim .intervalx = (xmin , xmax )
5923
5924
elif orientation == 'vertical' :
5924
5925
ymin0 = max (_saved_bounds [1 ]* 0.9 , minimum )
5925
5926
ymax = self .dataLim .intervaly [1 ]
5927
+
5926
5928
for m in n :
5927
5929
if np .sum (m ) > 0 : # make sure there are counts
5928
5930
ymin = np .amin (m [m != 0 ])
5929
5931
# filter out the 0 height bins
5930
- ymin = max (ymin * 0.9 , minimum )
5932
+ ymin = max (ymin * 0.9 , minimum ) if not input_empty else minimum
5931
5933
ymin = min (ymin0 , ymin )
5932
5934
self .dataLim .intervaly = (ymin , ymax )
5933
5935
0 commit comments