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') cc = fig.get_children() cc2 = cc[2] sps = cc2.get_subplotspec() gs = sps.get_gridspec() gs._nrows matplotlib.colorbar.make_axes_gridspec?? matplotlib.gridspec.GridSpecFromSubplotSpec?? fig = figure() ax = fig.add_subplot(111) # matplotlib.colorbar.make_axes_gridspec(ax)[0]; 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) 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] gs2 = gs_from_sp_spec(3, 1, subplot_spec=gs[1], hspace=0., height_ratios=wh_ratios) print wh_ratios parent = ax parent.set_subplotspec(gs[0]) parent.update_params() parent.set_position(parent.figbox) parent.set_anchor((1.0, 0.5)) cax = fig.add_subplot(gs2[1]) cax.set_aspect(aspect, anchor=(0.0, 0.5), adjustable='box') fig