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

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)):
     # Load data from file
     data1_amp = np.loadtxt(fname[4*i])
     data1_phase = np.loadtxt(fname[4*i+1])
     data2_amp = np.loadtxt(fname[4*i+2])
     data2_phase = np.loadtxt(fname[4*i+3])

     # Display data using pcolor
     ax1 = fig1.add_subplot(len(fname)/4,4,4*i+1)
     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 = fig1.colorbar(pc1,ax=ax1,orientation='horizontal',pad=0.00)
     cb1.ax.set_xticklabels(range(5),fontsize=10)

     ax2 = fig1.add_subplot(len(fname)/4,4,4*i+2)
     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 = fig1.colorbar(pc2,ax=ax2,orientation='horizontal',pad=0.00, ticks=[-np.pi,-np.pi/2,0,np.pi/2,np.pi])
     cb2.ax.set_xticklabels(range(5),fontsize=10)

     ax3 = fig1.add_subplot(len(fname)/4,4,4*i+3)
     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 = fig1.colorbar(pc1,ax=ax3,orientation='horizontal',pad=0.00)
     cb3.ax.set_xticklabels(range(5),fontsize=10)

     ax4 = fig1.add_subplot(len(fname)/4,4,4*i+4)
     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.