matplotlib-users

 [Matplotlib-users] How to change yticks on colorbar? From: Mark Bakker - 2008-11-05 11:24:57 Attachments: Message as HTML ```Hello list - I am trying to change the yticks on my colorbar (in combination with contourf) and cannot figure out how to do it. Short example: x,y = meshgrid(linspace(0,10),linspace(0,10)) a = contourf(x,y,x,linspace(0,10,6)) b = colorbar(a) This gives a nice colorbar, with ticks at 0,2,4,6,8,10 But I want labels only at 0,5,10. So I thought I can change that as: b.ax.set_yticks([0,5,10]) draw() But this gives really wacky results (totally messes up the colorbar), so that doesn't seem to be the way to do it. Can anybody tell me the correct way to do it? Thanks, Mark ```
 Re: [Matplotlib-users] How to change yticks on colorbar? From: Stan West - 2008-11-05 15:00:32 Attachments: Message as HTML ```From: Mark Bakker [mailto:markbak@...] Sent: Wednesday, November 05, 2008 06:25 Hello list - I am trying to change the yticks on my colorbar (in combination with contourf) and cannot figure out how to do it. Short example: x,y = meshgrid(linspace(0,10),linspace(0,10)) a = contourf(x,y,x,linspace(0,10,6)) b = colorbar(a) This gives a nice colorbar, with ticks at 0,2,4,6,8,10 But I want labels only at 0,5,10. So I thought I can change that as: b.ax.set_yticks([0,5,10]) draw() But this gives really wacky results (totally messes up the colorbar), so that doesn't seem to be the way to do it. Can anybody tell me the correct way to do it? Thanks, Mark Try b = colorbar(a, ticks=linspace(0, 10, 3)) Documentation is at http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.colorbar. ```
 Re: [Matplotlib-users] How to change yticks on colorbar? From: Mark Bakker - 2008-11-06 15:47:55 Attachments: Message as HTML ```Thanks Stan. I read the docs (which are quite nice), but couldn't find a way to set the ticks after the fact. But your method worked, Mark On Wed, Nov 5, 2008 at 4:00 PM, Stan West wrote: > *From:* Mark Bakker [mailto:markbak@...] > *Sent:* Wednesday, November 05, 2008 06:25 > Hello list - > > I am trying to change the yticks on my colorbar (in combination with > contourf) and cannot figure out how to do it. > > Short example: > > x,y = meshgrid(linspace(0,10),linspace(0,10)) > a = contourf(x,y,x,linspace(0,10,6)) > b = colorbar(a) > > This gives a nice colorbar, with ticks at 0,2,4,6,8,10 > > But I want labels only at 0,5,10. So I thought I can change that as: > > b.ax.set_yticks([0,5,10]) > draw() > > But this gives really wacky results (totally messes up the colorbar), so > that doesn't seem to be the way to do it. > > Can anybody tell me the correct way to do it? > > Thanks, Mark > > Try > > b = colorbar(a, ticks=linspace(0, 10, 3)) > > Documentation is at > http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.colorbar > . > ```
 Re: [Matplotlib-users] How to change yticks on colorbar? From: Stan West - 2008-11-06 16:18:44 Attachments: Message as HTML ```From: Mark Bakker [mailto:markbak@...] Sent: Thursday, November 06, 2008 10:48 Thanks Stan. I read the docs (which are quite nice), but couldn't find a way to set the ticks after the fact. But your method worked, Mark It seems to me that setting the ticks after the fact is more difficult, but the following appears to work: import matplotlib as mpl b.locator = mpl.ticker.FixedLocator([0, 5, 10]) b.draw_all() # recalculate the colorbar draw() Stan ```