change ticklabels in colorbar in PyPlot

160 views
Skip to first unread message

yhorie

unread,
Oct 12, 2014, 6:12:21 PM10/12/14
to julia...@googlegroups.com

I use PyPlot for plotting. Can somebody give an example to manipulate the ticklabels in colorbar?

using PyPlot 
data = pi * rand(10, 10)
imshow(data)
cbar = colorbar(ticks=[0, pi])


I can find a similar example in matplotlib, but unable to reproduce it...

http://matplotlib.org/examples/pylab_examples/colorbar_tick_labelling_demo.html

-Yu

Daniel Høegh

unread,
Oct 13, 2014, 8:25:30 AM10/13/14
to julia...@googlegroups.com
You just need to make sure the ticks you would like is within the range:
using PyPlot
data = pi*rand(10, 10)
imshow(data,vmin=0, vmax=pi)

yhorie

unread,
Oct 13, 2014, 11:06:45 AM10/13/14
to julia...@googlegroups.com
Thanks. But how do you change the ticklabel as I want? Say, I like to set the label "0" to "\pi".

Daniel Høegh

unread,
Oct 13, 2014, 1:29:42 PM10/13/14
to julia...@googlegroups.com
I just did the exact same as the example then i got it working and then changed it to you example.

using PyPlot

fig, ax = subplots()
data = pi*rand(10, 10)
cax = ax[:imshow](data,vmin=0, vmax=pi)
cbar = fig[:colorbar](cax, ticks=[0, pi])
cbar[:ax][:set_yticklabels]([ "0", "\$\\pi\$"])

Message has been deleted

yhorie

unread,
Oct 13, 2014, 3:53:24 PM10/13/14
to julia...@googlegroups.com
Thanks! That's what I wanted.

Reply all
Reply to author
Forward
0 new messages