simple colorbar question

I have two quick questions about colorbars in matplotlib. The first is related to the size of the colorbar. I would like to have square axes for a plot, so I use:

ax=fig.add_subplot(1,2,1)

pc=ax.pcolor(X,Z,P2)

ax.set_aspect(1./ax.get_data_ratio())

cb=pylab.colorbar(pc,orientation=‘vertical’)

However, here I find that the colorbar is as long as the original image rather than the scaled image. Is there a good way around this?

pylab.axis(‘equal’)

and

pylab.axis(‘scaled’)

have not helped.

The second question is related to the choice of tickmarks for the colorbar. If I would like to have only say 4 ticks on colorbar, I tried:

cb.ax.xaxis.set_major_locator(MaxNLocator(4)), however, the range for the colorbar is now incorrect. Suggestions? I am using

version 0.99.0

Thanks,

William

There is no automatic way (that are implemented in matplotlib) to
adjust the location of the colorbar axes to match that of the parent
axes. Thus you need to manually do this.

The axes_grid toolkit (which is included in 0.99) provide some helper
function for it though. Check out the function
"demo_locatable_axes_easy" in the example below.

http://matplotlib.sourceforge.net/examples/axes_grid/demo_axes_divider.html

The best way to change the colorbar tick is to provide *ticks*
parameter when you create the colorbar. Changing ticks of the existing
colorbar is a bit tricky.

Regards,

-JJ

···

On Tue, Dec 15, 2009 at 2:11 PM, william ratcliff <william.ratcliff@...287...> wrote:

I have two quick questions about colorbars in matplotlib. The first is
related to the size of the colorbar. I would like to have square axes for a
plot, so I use:
ax=fig.add_subplot(1,2,1)
pc=ax.pcolor(X,Z,P2)
ax.set_aspect(1./ax.get_data_ratio())
cb=pylab.colorbar(pc,orientation='vertical')
However, here I find that the colorbar is as long as the original image
rather than the scaled image. Is there a good way around this?
pylab.axis('equal')
and
pylab.axis('scaled')
have not helped.
The second question is related to the choice of tickmarks for the colorbar.
If I would like to have only say 4 ticks on colorbar, I tried:
cb.ax.xaxis.set_major_locator(MaxNLocator(4)), however, the range for the
colorbar is now incorrect. Suggestions? I am using
version 0.99.0
Thanks,
William
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users