# Custom ticklabels on colorbar

Daniel Platz <mail.to.daniel.platz@...982...> writes:

t = cb4.ax.get_xticklabels()
for j in t:
j.set_text(r'$\pi$')
j.set_fontsize(10)
j.set_family('serif')

Try cb4.ax.set_xticklabels([r'$-\pi$', ...]); draw()

Another problem is that I want to adjust the fontsize of the colorbar
ticklabels on four subplots. This only works for the last two subplots
with the syntax shown above. The same syntax has no effect on the first
two subplots.

You should be able to pass font properties to set_xticklabels. If that
doesn't work, please post a complete example.

···

--
Jouni K. Sepp�nen
http://www.iki.fi/jks

The setting of the new ticklabels works now. But the first label is attached to the second tick. I tried to adapt the clim range by using the vmin and vmax option of pcolor but it did not help.

I also still have the problem that the changes are only performed on the last two subplots (in one loop run). The code of the plotting loop is:
for i in range(len(fname)):

# Display data using pcolor
pc1 = ax1.pcolorfast(data1_amp,cmap=mpl.cm.Oranges)
ax1.set_xlim((0,250))
ax1.set_ylim((0,256))
ax1.set_xticklabels('')
ax1.set_yticklabels('')
cb1.ax.set_xticklabels(range(5),fontsize=10)

pc2 = ax2.pcolorfast(data1_phase,cmap=nat_per)
ax2.set_xlim((0,250))
ax2.set_ylim((0,256))
ax2.set_xticklabels('')
ax2.set_yticklabels('')
cb2.ax.set_xticklabels(range(5),fontsize=10)

pc3 = ax3.pcolorfast(data2_amp,cmap=mpl.cm.Oranges)
ax3.set_xlim((0,250))
ax3.set_ylim((0,256))
ax3.set_xticklabels('')
ax3.set_yticklabels('')
cb3.ax.set_xticklabels(range(5),fontsize=10)

pc4 = ax4.pcolorfast(data2_phase,cmap=nat_per,vmin=-np.pi-0.1,vmax=np.pi+0.001)
ax4.set_xlim((0,250))
ax4.set_ylim((0,256))
ax4.set_xticklabels('')
ax4.set_yticklabels('')
cb4 = fig1.colorbar(pc2,ax=ax4,orientation='horizontal',pad=0.00, ticks=[-np.pi, -np.pi/2, 0.0, np.pi/2, np.pi])
cb4.ax.set_xticklabels([r'$-\pi$', r'$-\frac{\pi}{2}$', r'$0$', r'$\frac{\pi}{2}$', r'$\pi$'],fontsize=10)

Daniel

Jouni K. Seppänen wrote:

···

Daniel Platz <mail.to.daniel.platz@...982...> writes:

t = cb4.ax.get_xticklabels()
for j in t:
j.set_text(r'$\pi$')
j.set_fontsize(10)
j.set_family('serif')

Try cb4.ax.set_xticklabels([r'$-\pi$', ...]); draw()

Another problem is that I want to adjust the fontsize of the colorbar ticklabels on four subplots. This only works for the last two subplots with the syntax shown above. The same syntax has no effect on the first two subplots.

You should be able to pass font properties to set_xticklabels. If that
doesn't work, please post a complete example.

2009/8/20 Daniel Platz <mail.to.daniel.platz@...982...>:
The setting of the new ticklabels works now. But the first label is
attached to the second tick. I tried to adapt the clim range by using
the vmin and vmax option of pcolor but it did not help.

Does this help?

http://matplotlib.sourceforge.net/examples/pylab_examples/colorbar_tick_labelling_demo.html

Cheers,
Scott

···

Jouni K. Seppänen wrote:

Daniel Platz <mail.to.daniel.platz@...982...> writes:

t = cb4.ax.get_xticklabels()
for j in t:
j.set_text(r'$\pi$')
j.set_fontsize(10)
j.set_family('serif')

Try cb4.ax.set_xticklabels([r'$-\pi$', ...]); draw()

Another problem is that I want to adjust the fontsize of the colorbar
ticklabels on four subplots. This only works for the last two subplots
with the syntax shown above. The same syntax has no effect on the first
two subplots.

You should be able to pass font properties to set_xticklabels. If that
doesn't work, please post a complete example.