In [146]:
from matplotlib.collections import EllipseCollection

x = np.arange(10)
y = np.arange(15)
X, Y = np.meshgrid(x, y)

XY = np.hstack((X.ravel()[:,np.newaxis], Y.ravel()[:,np.newaxis]))

ww = X/10.0
hh = Y/15.0
aa = X*9


fig, ax = plt.subplots()

ec = EllipseCollection(
                        ww,
                        hh,
                        aa,
                        units='x',
                        offsets=XY,
                        transOffset=ax.transData)
ec.set_array((X+Y).ravel())
ax.add_collection(ec)
ax.autoscale_view()
ax.set_xlabel('X')
ax.set_ylabel('y')
cbar = plt.colorbar(ec)
# cbar.set_label('X+Y')
In [147]:
cc = fig.get_children()
In [148]:
cc2 = cc[2]
In [149]:
sps = cc2.get_subplotspec()
In [150]:
gs = sps.get_gridspec()
In [151]:
gs._nrows
Out[151]:
3
In [158]:
matplotlib.colorbar.make_axes_gridspec??
In [157]:
matplotlib.gridspec.GridSpecFromSubplotSpec??
In [238]:
fig = figure()
ax = fig.add_subplot(111)
# matplotlib.colorbar.make_axes_gridspec(ax)[0];
In [239]:
kw = {}
orientation = kw.setdefault('orientation', 'vertical')
fraction = kw.pop('fraction', 0.15)
shrink = kw.pop('shrink', 1.0)
aspect = kw.pop('aspect', 20)

x1 = 1.0-fraction

# for shrinking
pad_s = (1.-shrink)*0.5
wh_ratios = [pad_s, shrink, pad_s]
pad = kw.pop('pad', 0.05)
wh_space = 2*pad/(1-pad)
In [245]:
gs = gs_from_sp_spec(1, 2,
                         subplot_spec=ax.get_subplotspec(),
                         wspace=wh_space,
                         width_ratios=[x1-pad, fraction]
                         )
print wh_space
print [x1 - pad, fraction]
0.105263157895
[0.7999999999999999, 0.15]

In [246]:
gs2 = gs_from_sp_spec(3, 1, subplot_spec=gs[1], hspace=0.,
                      height_ratios=wh_ratios)
print wh_ratios
[0.0, 1.0, 0.0]

In [242]:
parent = ax
parent.set_subplotspec(gs[0])
parent.update_params()
parent.set_position(parent.figbox)
parent.set_anchor((1.0, 0.5))
In [243]:
cax = fig.add_subplot(gs2[1])
cax.set_aspect(aspect, anchor=(0.0, 0.5), adjustable='box')
In [244]:
fig
Out[244]:
Back to top