@@ -4792,11 +4792,10 @@ def make_iterable(x):
4792
4792
if orientation == 'vertical' :
4793
4793
self ._process_unit_info (xdata = left , ydata = height , kwargs = kwargs )
4794
4794
if log :
4795
- self .set_yscale ('log' )
4795
+ self .set_yscale ('log' , nonposy = 'clip' )
4796
4796
# size width and bottom according to length of left
4797
4797
if _bottom is None :
4798
4798
if self .get_yscale () == 'log' :
4799
- bottom = [1e-100 ]
4800
4799
adjust_ylim = True
4801
4800
else :
4802
4801
bottom = [0 ]
@@ -4808,11 +4807,10 @@ def make_iterable(x):
4808
4807
elif orientation == 'horizontal' :
4809
4808
self ._process_unit_info (xdata = width , ydata = bottom , kwargs = kwargs )
4810
4809
if log :
4811
- self .set_xscale ('log' )
4810
+ self .set_xscale ('log' , nonposx = 'clip' )
4812
4811
# size left and height according to length of bottom
4813
4812
if _left is None :
4814
4813
if self .get_xscale () == 'log' :
4815
- left = [1e-100 ]
4816
4814
adjust_xlim = True
4817
4815
else :
4818
4816
left = [0 ]
@@ -8108,10 +8106,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8108
8106
hist_kwargs ['new' ] = True
8109
8107
8110
8108
n = []
8111
- mlast = None
8112
- # reversed order is necessary so when stacking histogram, first dataset is on top
8113
- # if histogram isn't stacked, this doesn't make any difference
8114
- for i in reversed (xrange (nx )):
8109
+ mlast = bottom
8110
+ for i in xrange (nx ):
8115
8111
# this will automatically overwrite bins,
8116
8112
# so that each histogram uses the same bins
8117
8113
m , bins = np .histogram (x [i ], bins , weights = w [i ], ** hist_kwargs )
@@ -8137,8 +8133,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8137
8133
else :
8138
8134
n = [m [slc ].cumsum ()[slc ] for m in n ]
8139
8135
8140
- n .reverse () # put them back in the right order
8141
-
8142
8136
patches = []
8143
8137
8144
8138
if histtype .startswith ('bar' ):
@@ -8175,24 +8169,34 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8175
8169
_barfunc = self .bar
8176
8170
8177
8171
for m , c in zip (n , color ):
8178
- patch = _barfunc (bins [:- 1 ]+ boffset , m , width ,
8172
+ if bottom is None :
8173
+ bottom = np .zeros (len (m ), np .float )
8174
+ if stacked :
8175
+ height = m - bottom
8176
+ else :
8177
+ height = m
8178
+ patch = _barfunc (bins [:- 1 ]+ boffset , height , width ,
8179
8179
align = 'center' , log = log ,
8180
8180
color = c , bottom = bottom )
8181
8181
patches .append (patch )
8182
+ if stacked :
8183
+ bottom [:] = m
8182
8184
boffset += dw
8183
8185
8184
8186
elif histtype .startswith ('step' ):
8185
- x = np .zeros ( 2 * len (bins ), np .float )
8186
- y = np .zeros ( 2 * len (bins ), np .float )
8187
+ # these define the perimeter of the polygon
8188
+ x = np .zeros ( 4 * len (bins )- 3 , np .float )
8189
+ y = np .zeros ( 4 * len (bins )- 3 , np .float )
8187
8190
8188
- x [0 ::2 ], x [1 ::2 ] = bins , bins
8191
+ x [0 :2 * len (bins )- 1 :2 ], x [1 :2 * len (bins )- 1 :2 ] = bins , bins [:- 1 ]
8192
+ x [2 * len (bins )- 1 :] = x [1 :2 * len (bins )- 1 ][::- 1 ]
8189
8193
8190
8194
if log :
8191
8195
if orientation == 'horizontal' :
8192
- self .set_xscale ('log' )
8196
+ self .set_xscale ('log' , nonposx = 'clip' )
8193
8197
logbase = self .xaxis ._scale .base
8194
8198
else : # orientation == 'vertical'
8195
- self .set_yscale ('log' )
8199
+ self .set_yscale ('log' , nonposy = 'clip' )
8196
8200
logbase = self .yaxis ._scale .base
8197
8201
8198
8202
# Setting a minimum of 0 results in problems for log plots
@@ -8219,19 +8223,37 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8219
8223
# overriding this
8220
8224
fill = (histtype == 'stepfilled' )
8221
8225
8222
- for m , c in zip (n , color ):
8223
- y [1 :- 1 :2 ], y [2 ::2 ] = m , m
8226
+ xvals , yvals = [], []
8227
+ for m in n :
8228
+ # starting point for drawing polygon
8229
+ y [0 ] = y [- 1 ]
8230
+ # top of the previous polygon becomes the bottom
8231
+ y [2 * len (bins )- 1 :] = y [1 :2 * len (bins )- 1 ][::- 1 ]
8232
+ # set the top of this polygon
8233
+ y [1 :2 * len (bins )- 1 :2 ], y [2 :2 * len (bins ):2 ] = m , m
8224
8234
if log :
8225
8235
y [y < minimum ]= minimum
8226
8236
if orientation == 'horizontal' :
8227
8237
x ,y = y ,x
8228
8238
8239
+ xvals .append (x .copy ())
8240
+ yvals .append (y .copy ())
8241
+
8242
+ # add patches in reverse order so that when stacking,
8243
+ # items lower in the stack are plottted on top of
8244
+ # items higher in the stack
8245
+ for x , y , c in reversed (zip (xvals , yvals , color )):
8229
8246
if fill :
8230
8247
patches .append ( self .fill (x , y ,
8231
- closed = False , facecolor = c ) )
8248
+ closed = False ,
8249
+ facecolor = c ) )
8232
8250
else :
8233
8251
patches .append ( self .fill (x , y ,
8234
- closed = False , edgecolor = c , fill = False ) )
8252
+ closed = False , edgecolor = c ,
8253
+ fill = False ) )
8254
+
8255
+ # we return patches, so put it back in the expected order
8256
+ patches .reverse ()
8235
8257
8236
8258
# adopted from adjust_x/ylim part of the bar method
8237
8259
if orientation == 'horizontal' :
0 commit comments