How to add extra ticks to colorbar

I have a colorbar which has some ticks, but I would like to add my own
ticks without replacing any of the existing ones. In addition, I
would like to give the ticks a different labels like "min" and "max".
Can someone show how this might be done?

Thanks,
Jeremy

http://matplotlib.sourceforge.net/examples/pylab_examples/colorbar_tick_labelling_demo.html
should give you some ideas to get started.

Cheers,
Scott

···

On 16 September 2010 22:52, Jeremy Conlin <jlconlin@...287...> wrote:

I have a colorbar which has some ticks, but I would like to add my own
ticks without replacing any of the existing ones. In addition, I
would like to give the ticks a different labels like "min" and "max".
Can someone show how this might be done?

Thanks for pointing me to that demo, it's a good one. However, I want
the ticks that are generated automatically, in addition to the extra
ones I add. The demo seems to show how I can define my own only.

Jeremy

···

On Fri, Sep 17, 2010 at 12:44 AM, Scott Sinclair <scott.sinclair.za@...287...> wrote:

On 16 September 2010 22:52, Jeremy Conlin <jlconlin@...287...> wrote:

I have a colorbar which has some ticks, but I would like to add my own
ticks without replacing any of the existing ones. In addition, I
would like to give the ticks a different labels like "min" and "max".
Can someone show how this might be done?

http://matplotlib.sourceforge.net/examples/pylab_examples/colorbar_tick_labelling_demo.html
should give you some ideas to get started.

While I haven’t tried this, so there might be a few extra things to do to make this work… You could first call

ticks = cbar.ax.get_yticks()

tickStrs = [label.get_text() for label in cbar.ax.get_yticklabels()]

to get the list of tick locations and the strings.
Then, insert any additional ticks at whatever locations you want in ‘ticks’.
Next, insert the desired strings at the same locations in ‘tickStrs’.

Then, update the tick locations and strings in cbar:

cbar.set_ticks(ticks, update_ticks=False)
cbar.set_ticklabels(tickStrs, update_ticks=True)

The use of update_ticks=False is to defer the actual processing of the tick data until later. This is to avoid conflicts with the differing lengths of tick locations and tick labels. The update would then occur at the end of set_ticklabels().

Note, I have not tested this, so there is no guarantee that this would work. Good luck!

Ben Root

···

On Fri, Sep 17, 2010 at 11:33 PM, Jeremy Conlin <jlconlin@…1972…> wrote:

On Fri, Sep 17, 2010 at 12:44 AM, Scott Sinclair > > <scott.sinclair.za@gmail.com> wrote:

On 16 September 2010 22:52, Jeremy Conlin <jlconlin@…287…> wrote:

I have a colorbar which has some ticks, but I would like to add my own

ticks without replacing any of the existing ones. In addition, I

would like to give the ticks a different labels like “min” and “max”.

Can someone show how this might be done?

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

should give you some ideas to get started.

Thanks for pointing me to that demo, it’s a good one. However, I want

the ticks that are generated automatically, in addition to the extra

ones I add. The demo seems to show how I can define my own only.

Jeremy