8000 First pass; seems to work. More testing needed · matplotlib/matplotlib@62aa006 · GitHub
[go: up one dir, main page]

Skip to content

Commit 62aa006

Browse files
committed
First pass; seems to work. More testing needed
1 parent 65f3906 commit 62aa006

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

lib/matplotlib/colorbar.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
11661166

11671167

11681168
@docstring.Substitution(make_axes_kw_doc)
1169-
def make_axes_gridspec(parent, **kw):
1169+
def make_axes_gridspec(parents, **kw):
11701170
'''
11711171
Resize and reposition a parent axes, and return a child axes
11721172
suitable for a colorbar. This function is similar to
@@ -1213,13 +1213,35 @@ def make_axes_gridspec(parent, **kw):
12131213
pad_s = (1. - shrink) * 0.5
12141214
wh_ratios = [pad_s, shrink, pad_s]
12151215

1216+
# make parents a 1-d ndarray if its not already...
1217+
parents = np.atleast_1d(parents).ravel()
1218+
# get the appropriate subplot spec. Loop through the parents.
1219+
gs0 = parents[0].get_subplotspec().get_gridspec()
1220+
minind = 10000
1221+
maxind = -10000
1222+
for parent in parents:
1223+
gs = parent.get_subplotspec().get_gridspec()
1224+
if gs == gs0:
1225+
ss = parent.get_subplotspec().get_geometry()
1226+
if ss[2]<minind:
1227+
minind = ss[2]
1228+
if ss[3]>maxind:
1229+
maxind = ss[3]
1230+
else:
1231+
pass
1232+
print(minind)
1233+
print(maxind)
1234+
subspec = gridspec.SubplotSpec(gs0,minind,maxind)
1235+
print(subspec)
1236+
print(subspec.get_geometry())
1237+
12161238
gs_from_subplotspec = gridspec.GridSpecFromSubplotSpec
12171239
if orientation == 'vertical':
12181240
pad = kw.pop('pad', 0.05)
12191241
wh_space = 2 * pad / (1 - pad)
12201242

12211243
gs = gs_from_subplotspec(1, 2,
1222-
subplot_spec=parent.get_subplotspec(),
1244+
subplot_spec=subspec,
12231245
wspace=wh_space,
12241246
width_ratios=[x1 - pad, fraction]
12251247
)
@@ -1229,6 +1251,8 @@ def make_axes_gridspec(parent, **kw):
12291251
hspace=0.,
12301252
height_ratios=wh_ratios,
12311253
)
1254+
print(gs)
1255+
print(gs2)
12321256

12331257
anchor = (0.0, 0.5)
12341258
panchor = (1.0, 0.5)
@@ -1237,7 +1261,7 @@ def make_axes_gridspec(parent, **kw):
12371261
wh_space = 2 * pad / (1 - pad)
12381262

12391263
gs = gs_from_subplotspec(2, 1,
1240-
subplot_spec=parent.get_subplotspec(),
1264+
subplot_spec=subspec,
12411265
hspace=wh_space,
12421266
height_ratios=[x1 - pad, fraction]
12431267
)
@@ -1252,12 +1276,13 @@ def make_axes_gridspec(parent, **kw):
12521276
anchor = (0.5, 1.0)
12531277
panchor = (0.5, 0.0)
12541278

1255-
parent.set_subplotspec(gs[0])
1256-
parent.update_params()
1257-
parent.set_position(parent.figbox)
1258-
parent.set_anchor(panchor)
1279+
for parent in parents:
1280+
parent.set_subplotspec(gs[0])
1281+
parent.update_params()
1282+
parent.set_position(parent.figbox)
1283+
parent.set_anchor(panchor)
12591284

1260-
fig = parent.get_figure()
1285+
fig = parents[0].get_figure()
12611286
cax = fig.add_subplot(gs2[1])
12621287
cax.set_aspect(aspect, anchor=anchor, adjustable='box')
12631288
return cax, kw

0 commit comments

Comments
 (0)
0