From: George N. <gn...@go...> - 2007-02-06 18:07:12
|
On 05/02/07, John Hunter <jd...@gm...> wrote: > On 2/5/07, Michael Lerner <mgl...@gm...> wrote: > > Hi, > > > > I have some data where I'd like almost all of it to be plotted with a > > LinearSegmentedColormap that I've made, but I have a few special > > values that I'd like to set to specific colors (white, in this case). > > So, I made a LinearSegmentedColormap that works pretty well, but I'm > > having trouble with the rest. I found a nice-looking example at > > > > http://www.scipy.org/Cookbook/Matplotlib/Plotting_Images_with_Special_Values > > > > But, it doesn't work for me. In particular, it complains a lot about > > _lut. I'm using matplotlib 0.87.7 on an intel Mac running OS X and > > python 2.4. > > On a very quick read, it appears that the sentinel map in that example > forgot to initialize the baseclass. Eg, you need > > class SentinelMap(Colormap): > def __init__(self, cmap, sentinels={}): > Colormap.__init__(self) # init the base class > # boilerplate stuff - rest of init function here > > See if that helps, and let us know. If you get it working, please fix > the wiki (you may have to sign up) and post your example along with > it. > > Otherwise, please post a complete code example and we'll see what we can do. > > JDH > > > > > > Can someone show me how to make a sentinel'd version of a > > LinearSegmentedColormap? > > > > Thank you, > > > > -Michael Lerner I had the same problem that you did with the sentinels.py. I modified the code so that it did work, and attach it here. you can test it by running it. It only works with numpy, because it uses fancy indexing. I'm pretty sure it's not done the fastest way. You first make up the colormap instance for the real data, without any sentinels. then use the colormap instance as an argument to the sentinel colormap. This is why it doesn't do a Colormap.__init__(self). Not sure that's really best, but i just followed the original method. HTH. George Nurser. |