tick labels in colorbar?

Hi,
thanks for the suggestion.

ax.set_xticks((-pi,pi))
ax.set_xticklabels(('$-\pi$','$\pi$'))

I guess color bars are a little special in the sense that

AttributeError: Colorbar instance has no attribute 'set_yticklabels'

The tick positions are given not by set_yticks either, but as an option

pylab.colorbar(ticks=(-pi,0,pi))

at the instatiation of the bar. It would indeed be very handy if the
bars acted like axes.

Cheers,
Nico

Hi Nico,

nontheless you can use the axes-method to display your preferred labels. The
colorbar has its axes as attribute 'ax' (see also my small example below):

cb.ax.set_yticklabels((r'$-\pi$', '0', r'$\pi$'))

Kind regards,
Matthias

···

On Monday 15 February 2010 09:28:10 Nico Schlömer wrote:

Hi,
thanks for the suggestion.

> ax.set_xticks((-pi,pi))
> ax.set_xticklabels(('$-\pi$','$\pi$'))

I guess color bars are a little special in the sense that

AttributeError: Colorbar instance has no attribute 'set_yticklabels'

The tick positions are given not by set_yticks either, but as an option

pylab.colorbar(ticks=(-pi,0,pi))

at the instatiation of the bar. It would indeed be very handy if the
bars acted like axes.

-----------------------------------
import matplotlib as mpl
mpl.rc('text', usetex=True)
import matplotlib.pyplot as plt
import numpy as np

ax = plt.axes()
plt.imshow(np.reshape(np.pi*np.arange(-2, 3, 0.5), (2, 5)))
cb = plt.colorbar()
cb.set_ticks((-np.pi, 0.0, np.pi))
cb.ax.set_yticklabels((r'$-\pi$', '0', r'$\pi$'))

plt.show()

cb.ax.set_yticklabels((r'$-\pi$', '0', r'$\pi$'))

Works like a charm. Thanks!

--Nico