Custom ticklabels on colorbar

2009/8/21 Daniel Platz <mail.to.daniel.platz@...982...>:
I just realized that I did not give the correct plot object when creating
the colorbar. Now it works perfectly to pass arguments by set_xticklabels().

However, another question just arose. To format the numbers on the tick
labels I tried to pass a format string when creating the colorbar with the
format parameter. But it has no effect. The same when I give a
FormatStrFormatter object. I also tried to use
cb.ax.axis.set_major_formatter(). The effect of this was. That it sets the
labels to the range between 0 and 1. Is there a solution for this problem
besides entering the tick labels manually?

Scott Sinclair wrote:

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

Hi Daniel,

It's hard for me to see what's happening here without a simple
standalone code example to illustrate your problem. Trying to
reproduce what you're seeing with a simple example will often reveal
where you're going wrong..

Also note that the default on this mailing list is not to send replies
to the list. Please use "Reply to all" so that your response goes to
the entire list and not directly to me, you're more likely to get a
helpful response that way. I'm sending this to the list, hopefully
someone can help you to resolve the issue.

Cheers,
Scott

The tick locator and tick formatter needs to be passed during the
colorbar creation. Otherwise,
it gets very tricky to deal with. This is because the data coordinate
of the colorbar axes is not directly associated with the ticklabels.

If passing the formatter during the colorbar creation has no effect,
this should be filed as a bug. Please post a small standalone example
that reproduces your problem. Also, please report your version of
matplotlib. If you're using older version, I recommend you to test it
with newer version.

Just in case, my quick test worked fine.

imshow([[1,2],[2,3]])
cb=colorbar(format=r"$%2.1f\%%$")

-JJ

···

On Fri, Aug 21, 2009 at 10:01 AM, Scott Sinclair<scott.sinclair.za@...287...> wrote:

I just realized that I did not give the correct plot object when creating
the colorbar. Now it works perfectly to pass arguments by set_xticklabels().

However, another question just arose. To format the numbers on the tick
labels I tried to pass a format string when creating the colorbar with the
format parameter. But it has no effect. The same when I give a
FormatStrFormatter object. I also tried to use
cb.ax.axis.set_major_formatter(). The effect of this was. That it sets the
labels to the range between 0 and 1. Is there a solution for this problem
besides entering the tick labels manually?

Jae-Joon Lee wrote:

I just realized that I did not give the correct plot object when creating
the colorbar. Now it works perfectly to pass arguments by set_xticklabels().

However, another question just arose. To format the numbers on the tick
labels I tried to pass a format string when creating the colorbar with the
format parameter. But it has no effect. The same when I give a
FormatStrFormatter object. I also tried to use
cb.ax.axis.set_major_formatter(). The effect of this was. That it sets the
labels to the range between 0 and 1. Is there a solution for this problem
besides entering the tick labels manually?

The tick locator and tick formatter needs to be passed during the
colorbar creation. Otherwise,
it gets very tricky to deal with. This is because the data coordinate
of the colorbar axes is not directly associated with the ticklabels.

If passing the formatter during the colorbar creation has no effect,
this should be filed as a bug. Please post a small standalone example
that reproduces your problem. Also, please report your version of
matplotlib. If you're using older version, I recommend you to test it
with newer version.

Just in case, my quick test worked fine.

imshow([[1,2],[2,3]])
cb=colorbar(format=r"$%2.1f\%%$")

-JJ

I just tried this but it did not work for me. The code that I am using looks like this

     ax1 = fig1.add_subplot(3,len(fname)/2,i+1,frameon=False)
     temp = np.linspace(data1_amp.min(),data1_amp.max(),3)
     pc1 = ax1.imshow(data1_amp,cmap=nat,vmin=temp[0],vmax=temp[-1])
     ax1.set_xlim((0,250))
     ax1.set_ylim((0,256))
     ax1.set_xticks([])
     ax1.set_yticks([])
     ax1.set_xticklabels('')
     ax1.set_yticklabels('')
     if i==0:
         ax1.set_ylabel('Amplitude [mV]',family='serif',size=10,weight='bold')
     ax1.set_title(title[i],family='serif',fontsize=10,weight='bold')
     cb1 = fig1.colorbar(pc1,ax=ax1,orientation='horizontal',pad=0.025,ticks=temp,format=r"$%2.1f\%%$")
     cb1.ax.set_xticklabels(temp,fontsize=10,family='serif')
     setp(cb1.ax.get_xticklines(),visible=False)
     plt.draw()
     a = ax1.get_position().get_points()
     b = cb1.ax.get_position().get_points()
     temp = [a[0,0], b[0,1], (a[1,0]-a[0,0]), (b[1,1]-b[0,1])]
     cb1.ax.set_position(temp)

I am using matplotlib 0.98.5.2. If anyone has an idea I would be very glad if you can post here.

Thanks in advance

Daniel

···

On Fri, Aug 21, 2009 at 10:01 AM, Scott > Sinclair<scott.sinclair.za@...287...> wrote:

Please, take your time and post a "standalone" code that reproduces
your problem so that others can actually test. Also, please describe
what results you have and why they are wrong.

···

On Tue, Aug 25, 2009 at 4:08 AM, Daniel Platz<mail.to.daniel.platz@...982...> wrote:

fig1.colorbar(pc1,ax=ax1,orientation='horizontal',pad=0.025,ticks=temp,format=r"$%2.1f\%%$")
cb1.ax.set_xticklabels(temp,fontsize=10,family='serif')

The set_xticklabels command actually overrides the format setting you
specified in the colorbar call, which might be the reason that the
script does not work as you intended. But, it is hard to tell without
the runnable code.

-JJ