Re: [Matplotlib-users] tick labels in colorbar?

2010-02-15 Thread Nico Schlömer
Hi,
thanks for the suggestion.

 ax.set_xticks((-pi,pi))
 ax.set_xticklabels(('$-\pi$','$\pi$'))

I guess color bars are a little special in the sense that

   AttributeError: Colorbar instance has no attribute 'set_yticklabels'

The tick positions are given not by set_yticks either, but as an option

   pylab.colorbar(ticks=(-pi,0,pi))

at the instatiation of the bar. It would indeed be very handy if the
bars acted like axes.

Cheers,
Nico

--
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] tick labels in colorbar?

2010-02-15 Thread Matthias Michler
On Monday 15 February 2010 09:28:10 Nico Schlömer wrote:
 Hi,
 thanks for the suggestion.

  ax.set_xticks((-pi,pi))
  ax.set_xticklabels(('$-\pi$','$\pi$'))

 I guess color bars are a little special in the sense that

AttributeError: Colorbar instance has no attribute 'set_yticklabels'

 The tick positions are given not by set_yticks either, but as an option

pylab.colorbar(ticks=(-pi,0,pi))

 at the instatiation of the bar. It would indeed be very handy if the
 bars acted like axes.

Hi Nico,

nontheless you can use the axes-method to display your preferred labels. The 
colorbar has its axes as attribute 'ax' (see also my small example below):

cb.ax.set_yticklabels((r'$-\pi$', '0', r'$\pi$'))

Kind regards,
Matthias

---
import matplotlib as mpl
mpl.rc('text', usetex=True)
import matplotlib.pyplot as plt
import numpy as np

ax = plt.axes()
plt.imshow(np.reshape(np.pi*np.arange(-2, 3, 0.5), (2, 5)))
cb = plt.colorbar()
cb.set_ticks((-np.pi, 0.0, np.pi))
cb.ax.set_yticklabels((r'$-\pi$', '0', r'$\pi$'))

plt.show()

--
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] tick labels in colorbar?

2010-02-15 Thread Nico Schlömer
 cb.ax.set_yticklabels((r'$-\pi$', '0', r'$\pi$'))

Works like a charm. Thanks!

--Nico

--
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] tick labels in colorbar?

2010-02-14 Thread Nico Schlömer
Hi,

I'm plotting a colorbar with

pylab.colorbar(ticks=(-pi,0,pi))

and trying to add proper \pi labels to it. Couldn't find out how to
do that from the manual -- any hints here?

Cheers,
Nico

--
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] tick labels in colorbar?

2010-02-14 Thread Philipp Bender
Hi Nico,

I didn't test it, but maybe with something like that:

rc('text', usetex=True)

[taken from 
http://matplotlib.sourceforge.net/plot_directive/mpl_examples/pylab_examples/tex_demo.py]

ax.set_xticks((-pi,pi))
ax.set_xticklabels(('$-\pi$','$\pi$'))

[taken from 
http://matplotlib.sourceforge.net/examples/pylab_examples/integral_demo.html]

Cheers,
Philipp

--
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users