8000 Aded comments and cleaned up · matplotlib/matplotlib@1c5a14e · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c5a14e

Browse files
committed
Aded comments and cleaned up
1 parent 031d35
8000
6 commit 1c5a14e

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

lib/matplotlib/colorbar.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ def make_axes_gridspec(parents, **kw):
11791179
'''
11801180
Resize and reposition a parent axes, and return a child axes
11811181
suitable for a colorbar. This function is similar to
1182-
make_axes. Prmary differences are
1182+
make_axes. Primary differences are
11831183
11841184
* *make_axes_gridspec* only handles the *orientation* keyword
11851185
and cannot handle the "location" keyword.
@@ -1224,10 +1224,11 @@ def make_axes_gridspec(parents, **kw):
12241224

12251225
# make parents a 1-d ndarray if its not already...
12261226
parents = np.atleast_1d(parents).ravel()
1227-
# get the appropriate subplot spec. Loop through the parents.
1227+
# For the subplotspec that these axes belong to, loop through and get
1228+
# the maximum and minimum index into the subplotspec. The result is the
1229+
# size the new gridspec that we will create must be.
12281230
gsp0 = parents[0].get_subplotspec().get_gridspec()
1229-
minind = 10000
1230-
maxind = -10000
1231+
minind = 10000;maxind = -10000
12311232
for parent in parents:
12321233
gsp = parent.get_subplotspec().get_gridspec()
12331234
if gsp == gsp0:
@@ -1238,47 +1239,37 @@ def make_axes_gridspec(parents, **kw):
12381239
if ss[3]>maxind:
12391240
maxind = ss[3]
12401241
else:
1241-
pass
1242-
# get from maxind and minind to nrows and ncols..
1242+
raise NotImplementedError('List of axes passed to colorbar must be from the same gridspec or call to plt.subplots')
1243+
# map the extent of the gridspec from indices to rows and columns.
1244+
# We need this below to assign the parents into the new gridspec.
12431245
ncols0 = gsp0.get_geometry()[1]
1244-
print(ncols0)
1245-
print(maxind)
1246-
12471246
minrow,mincol=index2rowcolunm(minind,ncols0)
12481247
maxrow,maxcol=index2rowcolunm(maxind,ncols0)
1249-
print('mnind %d maxind %d'%(minind,maxind))
1250-
print('mncol %d maxcol %d'%(mincol,maxcol))
1251-
print('mnrow %d maxrow %d'%(minrow,maxrow))
12521248
nrows = maxrow-minrow+1
12531249
ncols = maxcol-mincol+1
12541250

1255-
print('nrows %d ncols %d'%(nrows,ncols))
1256-
print(minind)
1257-
print(maxind)
1251+
# this is subplot spec the region that we need to resize and add
1252+
# a colorbar to.
12581253
subspec = gridspec.SubplotSpec(gsp0,minind,maxind)
1259-
print('GSP0')
1260-
print(gsp0.get_geometry())
1261-
print(subspec)
1262-
print(subspec.get_geometry())
12631254

12641255
gs_from_subplotspec = gridspec.GridSpecFromSubplotSpec
12651256
if orientation == 'vertical':
12661257
pad = kw.pop('pad', 0.05)
12671258
wh_space = 2 * pad / (1 - pad)
12681259

1260+
# split the subplotspec containing parents into two, with one only
1261+
# `fraction` wide for the colorbar, and the other with some padding.
12691262
gs = gs_from_subplotspec(1, 2,
12701263
subplot_spec=subspec,
12711264
wspace=wh_space,
12721265
width_ratios=[x1 - pad, fraction]
12731266
)
1274-
1267+
# center the colorbar vertically.
12751268
gs2 = gs_from_subplotspec(3, 1,
12761269
subplot_spec=gs[1],
12771270
hspace=0.,
12781271
height_ratios=wh_ratios,
12791272
)
1280-
print(gs)
1281-
print(gs2)
12821273

12831274
anchor = (0.0, 0.5)
12841275
panchor = (1.0, 0.5)
@@ -1310,18 +1301,22 @@ def make_axes_gridspec(parents, **kw):
13101301
for parent in parents:
13111302
geo=parent.get_subplotspec().get_geometry()
13121303
ncol0 = geo[1]
1313-
print("Parent Geo:")
1314-
print(geo)
1304+
1305+
# remap the old min gridspec index (geo[2]) into a new
1306+
# index.
13151307
oldrow,oldcol = index2rowcolunm(geo[2],ncol0)
13161308
newrow = oldrow-minrow+1
13171309
newcol = oldcol-mincol+1
13181310
newminind = rowcolunm2index(newrow,newcol,ncols)
1311+
1312+
# remap the old max gridspec index (geo[3]) into a new
1313+
# index.
13191314
oldrow,oldcol = index2rowcolunm(geo[3],ncol0)
13201315
newrow = oldrow-minrow+1
13211316
newcol = oldcol-mincol+1
13221317
newmaxind = rowcolunm2index(newrow,newcol,ncols)
1323-
print('newminind %d newmaxind %d'%(newminind,newmaxind))
13241318

1319+
# change the subplotspec for this parent.
13251320
parent.set_subplotspec(gridspec.SubplotSpec(gsnew,newminind,newmaxind))
13261321
parent.update_params()
13271322
parent.set_position(parent.figbox)

0 commit comments

Comments
 (0)
0