def layoutcolorbarsingle(ax, cax, shrink, aspect, location, pad=0.05): """ Do the layout for a colorbar, to not oeverly pollute colorbar.py `pad` is in fraction of the original axis size. """ axlb = ax._layoutbox axpos = ax._poslayoutbox axsslb = ax.get_subplotspec()._layoutbox lb = layoutbox.LayoutBox( parent=axsslb, name=axsslb.name + '.cbar', artist=cax) if location in ('left', 'right'): lbpos = layoutbox.LayoutBox( parent=lb, name=lb.name + '.pos', tightwidth=False, pos=True, subplot=False, artist=cax) if location == 'right': # arrange to right of parent axis layoutbox.hstack([axlb, lb], padding=pad * axlb.width, strength='strong') else: layoutbox.hstack([lb, axlb], padding=pad * axlb.width) # constrain the height and center... layoutbox.match_heights([axpos, lbpos], [1, shrink]) layoutbox.align([axpos, lbpos], 'v_center') # set the width of the pos box lbpos.constrain_width(shrink * axpos.height * (1/aspect), strength='strong') elif location in ('bottom', 'top'): lbpos = layoutbox.LayoutBox( parent=lb, name=lb.name + '.pos', tightheight=True, pos=True, subplot=False, artist=cax) if location == 'bottom': layoutbox.vstack([axlb, lb], padding=pad * axlb.height) else: layoutbox.vstack([lb, axlb], padding=pad * axlb.height) # constrain the height and center... layoutbox.match_widths([axpos, lbpos], [1, shrink], strength='strong') layoutbox.align([axpos, lbpos], 'h_center') # set the height of the pos box lbpos.constrain_height(axpos.width * aspect * shrink, strength='medium') return lb, lbpos
def layoutcolorbarsingle(ax, cax, shrink, aspect, location, pad=0.05): """ Do the layout for a colorbar, to not overly pollute colorbar.py *pad* is in fraction of the original axis size. """ axlb = ax._layoutbox axpos = ax._poslayoutbox axsslb = ax.get_subplotspec()._layoutbox lb = layoutbox.LayoutBox( parent=axsslb, name=axsslb.name + '.cbar', artist=cax) if location in ('left', 'right'): lbpos = layoutbox.LayoutBox( parent=lb, name=lb.name + '.pos', tightwidth=False, pos=True, subplot=False, artist=cax) if location == 'right': # arrange to right of parent axis layoutbox.hstack([axlb, lb], padding=pad * axlb.width, strength='strong') else: layoutbox.hstack([lb, axlb], padding=pad * axlb.width) # constrain the height and center... layoutbox.match_heights([axpos, lbpos], [1, shrink]) layoutbox.align([axpos, lbpos], 'v_center') # set the width of the pos box lbpos.constrain_width(shrink * axpos.height * (1/aspect), strength='strong') elif location in ('bottom', 'top'): lbpos = layoutbox.LayoutBox( parent=lb, name=lb.name + '.pos', tightheight=True, pos=True, subplot=False, artist=cax) if location == 'bottom': layoutbox.vstack([axlb, lb], padding=pad * axlb.height) else: layoutbox.vstack([lb, axlb], padding=pad * axlb.height) # constrain the height and center... layoutbox.match_widths([axpos, lbpos], [1, shrink], strength='strong') layoutbox.align([axpos, lbpos], 'h_center') # set the height of the pos box lbpos.constrain_height(axpos.width * aspect * shrink, strength='medium') return lb, lbpos