@@ -1164,12 +1164,15 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
1164
1164
cax .set_aspect (aspect , anchor = anchor , adjustable = 'box' )
1165
1165
return cax , kw
1166
1166
1167
+
1167
1168
# helper functions for row,col to index.
1168
- def index2rowcolunm (index ,ncols ):
1169
+ def index2rowcolunm (index , ncols ):
1169
1170
col = index % ncols + 1
1170
1171
row = int (np .floor (index / ncols )+ 1 )
1171
- return row ,col
1172
- def rowcolunm2index (row ,col ,ncols ):
1172
+ return row , col
1173
+
1174
+
1175
+ def rowcolunm2index (row , col , ncols ):
1173
1176
index = col - 1 + (row - 1 )* ncols
1174
1177
return index
1175
1178
@@ -1228,17 +1231,21 @@ def make_axes_gridspec(parents, **kw):
1228
1231
# the maximum and minimum index into the subplotspec. The result is the
1229
1232
# size the new gridspec that we will create must be.
1230
1233
gsp0 = parents [0 ].get_subplotspec ().get_gridspec ()
1231
- minind = 10000 ;maxind = - 10000
1234
+ minind = 10000
1235
+ maxind = - 10000
1232
1236
for parent in parents :
1233
1237
gsp = parent .get_subplotspec ().get_gridspec ()
1234
1238
if gsp == gsp0 :
1235
- ss = parent .get_subplotspec ().get_geometry ()
1236
- if ss [2 ]< minind :
1239
+ ss = list (parent .get_subplotspec ().get_geometry ())
1240
+ if ss [3 ] is None :
1241
+ ss [3 ] = ss [2 ]
1242
+ if ss [2 ] < minind :
1237
1243
minind = ss [2 ]
1238
- if ss [3 ]> maxind :
1244
+ if ss [3 ] > maxind :
1239
1245
maxind = ss [3 ]
1240
1246
else :
1241
- raise NotImplementedError ('List of axes passed to colorbar must be from the same gridspec or call to plt.subplots' )
1247
+ raise NotImplementedError ('List of axes passed to colorbar '
1248
+ 'must be from the same gridspec or call to plt.subplots' )
1242
1249
# map the extent of the gridspec from indices to rows and columns.
1243
1250
# We need this below to assign the parents into the new gridspec.
1244
1251
ncols0 = gsp0 .get_geometry ()[1 ]
@@ -1249,7 +1256,7 @@ def make_axes_gridspec(parents, **kw):
1249
1256
1250
1257
# this is subplot spec the region that we need to resize and add
1251
1258
# a colorbar to.
1252
- subspec = gridspec .SubplotSpec (gsp0 ,minind ,maxind )
1259
+ subspec = gridspec .SubplotSpec (gsp0 , minind , maxind )
1253
1260
1254
1261
gs_from_subplotspec = gridspec .GridSpecFromSubplotSpec
1255
1262
if orientation == 'vertical' :
@@ -1310,13 +1317,17 @@ def make_axes_gridspec(parents, **kw):
1310
1317
1311
1318
# remap the old max gridspec index (geo[3]) into a new
1312
1319
# index.
1313
- oldrow , oldcol = index2rowcolunm (geo [3 ], ncol0 )
1314
- newrow = oldrow - minrow + 1
1315
- newcol = oldcol - mincol + 1
1316
- newmaxind = rowcolunm2index (newrow , newcol , ncols )
1320
+ if geo [3 ] is None :
1321
+ newmaxind = newminind
1322
+ else :
1323
+ oldrow , oldcol = index2rowcolunm (geo [3 ], ncol0 )
1324
+ newrow = oldrow - minrow + 1
1325
+ newcol = oldcol - mincol + 1
1326
+ newmaxind = rowcolunm2index (newrow , newcol , ncols )
1317
1327
1318
1328
# change the subplotspec for this parent.
1319
- parent .set_subplotspec (gridspec .SubplotSpec (gsnew , newminind , newmaxind ))
1329
+ parent .set_subplotspec (
1330
+ gridspec .SubplotSpec (gsnew , newminind , newmaxind ))
1320
1331
parent .update_params ()
1321
1332
parent .set_position (parent .figbox )
1322
1333
parent .set_anchor (panchor )
0 commit comments