Skip to content

Commit a7e484c

Browse files
committed
Fixed subplotspec geometry having None, PEP8 errors
1 parent 6788e71 commit a7e484c

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

lib/matplotlib/colorbar.py

+25-14
Original file line numberDiff line numberDiff line change
@@ -1164,12 +1164,15 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
11641164
cax.set_aspect(aspect, anchor=anchor, adjustable='box')
11651165
return cax, kw
11661166

1167+
11671168
# helper functions for row,col to index.
1168-
def index2rowcolunm(index,ncols):
1169+
def index2rowcolunm(index, ncols):
11691170
col = index%ncols + 1
11701171
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):
11731176
index = col-1+(row-1)*ncols
11741177
return index
11751178

@@ -1228,17 +1231,21 @@ def make_axes_gridspec(parents, **kw):
12281231
# the maximum and minimum index into the subplotspec. The result is the
12291232
# size the new gridspec that we will create must be.
12301233
gsp0 = parents[0].get_subplotspec().get_gridspec()
1231-
minind = 10000;maxind = -10000
1234+
minind = 10000
1235+
maxind = -10000
12321236
for parent in parents:
12331237
gsp = parent.get_subplotspec().get_gridspec()
12341238
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:
12371243
minind = ss[2]
1238-
if ss[3]>maxind:
1244+
if ss[3] > maxind:
12391245
maxind = ss[3]
12401246
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')
12421249
# map the extent of the gridspec from indices to rows and columns.
12431250
# We need this below to assign the parents into the new gridspec.
12441251
ncols0 = gsp0.get_geometry()[1]
@@ -1249,7 +1256,7 @@ def make_axes_gridspec(parents, **kw):
12491256

12501257
# this is subplot spec the region that we need to resize and add
12511258
# a colorbar to.
1252-
subspec = gridspec.SubplotSpec(gsp0,minind,maxind)
1259+
subspec = gridspec.SubplotSpec(gsp0, minind, maxind)
12531260

12541261
gs_from_subplotspec = gridspec.GridSpecFromSubplotSpec
12551262
if orientation == 'vertical':
@@ -1310,13 +1317,17 @@ def make_axes_gridspec(parents, **kw):
13101317

13111318
# remap the old max gridspec index (geo[3]) into a new
13121319
# 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)
13171327

13181328
# 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))
13201331
parent.update_params()
13211332
parent.set_position(parent.figbox)
13221333
parent.set_anchor(panchor)

0 commit comments

Comments
 (0)