axes_grid: labels on colorbar

Hi all,

I’m trying to use an AxesGrid to plot 5 images and a color bar. I can’t work out how to get labels on the colorbar, and none of the examples shows this. Can anyone help? I presume this is a simple thing, once one knows the correct command.

I’m creating the grid using the following code snippet, taking almost verbatim from the examples:

fig = plt.figure()

grid = AxesGrid(fig, 111, nrows_ncols = (1, 5), axes_pad = 0.05, share_all=True, cbar_mode=‘single’, cbar_location=‘right’, cbar_size=‘15%’)

for i in xrange(5):

im = grid[i].imshow(array[i])

plt.colorbar(im, cax=grid.cbar_axes[0])

but then it’s not clear how to switch on the labels. Things I’ve tried: normal colorbars come with them on by default. I’ve also found that grid.cbar_axes is a list of five elements, each of which is an CbarAxes, for which I can’t find documentation on the website, and doing grid.cbar_axes[0].set_yticks/set_yticklabels on at least the first and last elements of the list doesn’t work. Can anyone shed light on this? I bet it’s easy once I know the magic words.

Thanks,

Angus.

···


AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh

This is something that needs to be fixed in the next release.
Meanwhile, try something like,

cax = grid.cbar_axes[0]
cax.axis["right"].toggle(ticks=True, ticklabels=True, label=True)
cax.set_ylabel("Test")

Regards,

-JJ

···

On Tue, Apr 6, 2010 at 3:26 PM, Angus McMorland <amcmorl@...287...> wrote:

Hi all,
I'm trying to use an AxesGrid to plot 5 images and a color bar. I can't work
out how to get labels on the colorbar, and none of the examples shows this.
Can anyone help? I presume this is a simple thing, once one knows the
correct command.
I'm creating the grid using the following code snippet, taking almost
verbatim from the examples:
fig = plt.figure()
grid = AxesGrid(fig, 111, nrows_ncols = (1, 5), axes_pad = 0.05,
share_all=True, cbar_mode='single', cbar_location='right', cbar_size='15%')
for i in xrange(5):
im = grid[i].imshow(array[i])
plt.colorbar(im, cax=grid.cbar_axes[0])
but then it's not clear how to switch on the labels. Things I've tried:
normal colorbars come with them on by default. I've also found that
grid.cbar_axes is a list of five elements, each of which is an CbarAxes, for
which I can't find documentation on the website, and doing
grid.cbar_axes[0].set_yticks/set_yticklabels on at least the first and last
elements of the list doesn't work. Can anyone shed light on this? I bet it's
easy once I know the magic words.
Thanks,
Angus.
--
AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users