From: John H. <jdh...@ac...> - 2005-08-24 17:25:07
|
>>>>> "Jeff" == Jeff Whitaker <js...@fa...> writes: Jeff> Here's a patch against 0.83.2 that modifies colorbar to use Jeff> contourf instead of imshow (so that only those colors used Jeff> by contourf are shown on the colorbar). It also adds a few Jeff> keyword options to colorbar to 1) allow for linear spacing Jeff> of colors on the colorbar (even if the contour levels are Jeff> not linear), and 2) draw lines on the colorbar between the Jeff> individual colors. Eric and Jim: I think you have both been Jeff> hacking on colorbar, perhaps we could merge your changes Jeff> into this patch? Otherwise, if no one has any objections, Jeff> I'll commit this to CVS later this week. I haven't tested this but I did read over it and have one minor comment I tend to avoid catching all exceptions as in + try: + # mappable image is from contourf + clevs = array(mappable.levels.tolist() + [mappable.level_upper]) + iscontourf = True + except: + # from imshow or pcolor. + iscontourf = False + norm = mappable.norm + if norm.vmin is None or norm.vmax is None: + mappable.autoscale() + cmin = norm.vmin + cmax = norm.vmax + clevs = linspace(cmin, cmax, cmap.N) because they can lead to hard to track bugs. I suggest either catching an AttributeError or testing explicitly for ContourMappable, eg if isinstance(mappable, ContourMappable): # do something elif isinstance(mappable, ScalarMappable): # do something else else: Raise TypeError("don't know how to handle type %s"%type(mappable)) Thanks, JDH |