@@ -8108,10 +8108,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8108
8108
hist_kwargs ['new' ] = True
8109
8109
8110
8110
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 )):
8111
+ mlast = bottom
8112
+ for i in xrange (nx ):
8115
8113
# this will automatically overwrite bins,
8116
8114
# so that each histogram uses the same bins
8117
8115
m , bins = np .histogram (x [i ], bins , weights = w [i ], ** hist_kwargs )
@@ -8137,8 +8135,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8137
8135
else :
8138
8136
n = [m [slc ].cumsum ()[slc ] for m in n ]
8139
8137
8140
- n .reverse () # put them back in the right order
8141
-
8142
8138
patches = []
8143
8139
8144
8140
if histtype .startswith ('bar' ):
@@ -8175,17 +8171,23 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8175
8171
_barfunc = self .bar
8176
8172
8177
8173
for m , c in zip (n , color ):
8178
- patch = _barfunc (bins [:- 1 ]+ boffset , m , width ,
8174
+ patch = _barfunc (bins [:- 1 ]+ boffset , m , width , bottom ,
8179
8175
align = 'center' , log = log ,
8180
8176
color = c , bottom = bottom )
8181
8177
patches .append (patch )
8178
+ if stacked :
8179
+ if bottom is None :
8180
+ bottom = 0.0
8181
+ bottom += m
8182
8182
boffset += dw
8183
8183
8184
8184
elif histtype .startswith ('step' ):
8185
- x = np .zeros ( 2 * len (bins ), np .float )
8186
- y = np .zeros ( 2 * len (bins ), np .float )
8185
+ # these define the perimeter of the polygon
8186
+ x = np .zeros ( 4 * len (bins )- 3 , np .float )
8187
+ y = np .zeros ( 4 * len (bins )- 3 , np .float )
8187
8188
8188
- x [0 ::2 ], x [1 ::2 ] = bins , bins
8189
+ x [0 :2 * len (bins )- 1 :2 ], x [1 :2 * len (bins )- 1 :2 ] = bins , bins [:- 1 ]
8190
+ x [2 * len (bins )- 1 :] = x [1 :2 * len (bins )- 1 ][::- 1 ]
8189
8191
8190
8192
if log :
8191
8193
if orientation == 'horizontal' :
@@ -8219,19 +8221,37 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8219
8221
# overriding this
8220
8222
fill = (histtype == 'stepfilled' )
8221
8223
8222
- for m , c in zip (n , color ):
8223
- y [1 :- 1 :2 ], y [2 ::2 ] = m , m
8224
+ xvals , yvals = [], []
8225
+ for m in n :
8226
+ # starting point for drawing polygon
8227
+ y [0 ] = y [- 1 ]
8228
+ # top of the previous polygon becomes the bottom
8229
+ y [2 * len (bins )- 1 :] = y [1 :2 * len (bins )- 1 ][::- 1 ]
8230
+ # set the top of this polygon
8231
+ y [1 :2 * len (bins )- 1 :2 ], y [2 :2 * len (bins ):2 ] = m , m
8224
8232
if log :
8225
8233
y [y < minimum ]= minimum
8226
8234
if orientation == 'horizontal' :
8227
8235
x ,y = y ,x
8228
8236
8237
+ xvals .append (x .copy ())
8238
+ yvals .append (y .copy ())
8239
+
8240
+ # add patches in reverse order so that when stacking,
8241
+ # items lower in the stack are plottted on top of
8242
+ # items higher in the stack
8243
+ for x , y , c in reversed (zip (xvals , yvals , color )):
8229
8244
if fill :
8230
8245
patches .append ( self .fill (x , y ,
8231
- closed = False , facecolor = c ) )
8246
+ closed = False ,
8247
+ facecolor = c ) )
8232
8248
else :
8233
8249
patches .append ( self .fill (x , y ,
8234
- closed = False , edgecolor = c , fill = False ) )
8250
+ closed = False , edgecolor = c ,
8251
+ fill = False ) )
8252
+
8253
+ # we return patches, so put it back in the expected order
8254
+ patches .reverse ()
8235
8255
8236
8256
# adopted from adjust_x/ylim part of the bar method
8237
8257
if orientation == 'horizontal' :
0 commit comments