how to scale colorbar size to image size?

Hi all:

I'm looking for a simple way to scale a color bar so it will be the same
height as the image. It seems to work automatically if the image is at
least as tall as it is wide, but when it is wider than tall it seems to
scale to the width rather than height. (Shouldn't the default behavior
be to scale to height if the colorbar is vertical and width if its
horizontal?) One approach that I found at one point was something like
this:
fig = plt.figure(figsize=(11,5))
cax = fig.add_axes([0.9,0.1,0.01,0.8]) # axes for colorbar
ax = plt.subplot(111)
im = ax.imshow(image)
fig.colorbar(im,cax=cax)

but even with this method it seems that tweaking the figsize and
add_axes arguments. I've also fiddled with the shrink and fraction
keywords and have managed to get good results, but it seems so ad hoc.
Is there a better way?

Jon

Because of the design of the matplotlib, this is not straight forward
to implement.

While there could be a few ways to do it, you may try axes_grid1 toolkit.

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#colorbar-whose-height-or-width-in-sync-with-the-master-axes

Regards,

-JJ

ยทยทยท

On Tue, Apr 12, 2011 at 3:31 AM, Jonathan Slavin <jslavin@...1081...> wrote:

(Shouldn't the default behavior
be to scale to height if the colorbar is vertical and width if its
horizontal?)