|
From: Eric F. <ef...@ha...> - 2008-10-09 23:14:59
|
Zane Selvans wrote: > Zane Selvans <zane@...> writes: > >> I'm plotting a bunch of lines on a map. They're being colored >> according to the value of an attribute associated with the objects >> they represent, using a colormap. However, I also need to create a >> colorbar to act as a legend, describing what the colors of the lines >> means, in terms of values associated with that attribute. >> >> What's the easiest way to do that? > > I've found the matplotlib.colorbar.ColorbarBase class... and have been able to > use matplotlib.colorbar.make_axes() to create a somewhat acceptable set of axes > into which I can put a colorbar constructed from the same colormap that I'm > using to color the lines I'm plotting. However, I can't seem to get the tics > and axes on the colorbar to correspond to the values associated with the colors > - they only ever go from 0-1. I want them to go from, for instance, 0-180 > (degrees) in 20 or 30 degree intervals. It seemed like setting the keyword > arguments in ColorbarBase(boundaries=[0,180]) or values=linspace(0,180,10) or > something like that ought to have done the right thing... but no, and I don't > see any documentation on how these keywords are supposed to be used, in the > docstring or elsewhere... anyone know how they work? You probably want to use the ColorbarBase.add_lines() method; you can get an example of its use for line contours in the Colorbar class, and an example of the result is in examples/pylab_examples/contour_demo.py. Eric |