On Fri, Sep 17, 2010 at 11:33 PM, Jeremy Conlin <jlcon...@gmail.com> wrote:

> On Fri, Sep 17, 2010 at 12:44 AM, Scott Sinclair
> <scott.sinclair...@gmail.com> wrote:
> > On 16 September 2010 22:52, Jeremy Conlin <jlcon...@gmail.com> 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
>
>
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
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to