Trying

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.

Can someone show me how to make a sentinel'd version of a
LinearSegmentedColormap?

Thank you,

-Michael Lerner

···

--
Biophysics Graduate Student
Carlson Lab, University of Michigan
http://www.umich.edu/~mlerner http://lernerclan.net

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

···

On 2/5/07, Michael Lerner <mglerner@...287...> wrote:

Can someone show me how to make a sentinel'd version of a
LinearSegmentedColormap?

Thank you,

-Michael Lerner

--
Biophysics Graduate Student
Carlson Lab, University of Michigan
U-M Web Hosting http://lernerclan.net

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

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.

newsentinels2.py (6.22 KB)

···

On 05/02/07, John Hunter <jdh2358@...287...> wrote:

On 2/5/07, Michael Lerner <mglerner@...287...> 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

That works for me. Thanks. I was trying to muck around with _lut
directly and make a sentinel version of LinearSegmentedColormap. As I
didn't really know what I was doing, I was having some strange
results. Also, in case other folks don't realize this, you can
initialize this with a Colormap, LinearSegmentedColormap, etc.

I'd be happy to update the SciPy wiki. Is it customary to give credit
to various authors (obviously George Nurser and the original author,
not me) in the doc strings, wiki text or what?

Thanks,

-michael

···

On 2/6/07, George Nurser <gnurser@...982...> wrote:

On 05/02/07, John Hunter <jdh2358@...287...> wrote:
> On 2/5/07, Michael Lerner <mglerner@...287...> 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.

--
Biophysics Graduate Student
Carlson Lab, University of Michigan
U-M Web Hosting http://lernerclan.net

Please do.

I believe the original code was written by Andrew Straw; at least he
put it up on the wiki.

A word of warning: because the code replaces various Normalize
methods, it's not guaranteed to work with future mpl releases.

It would be nice if something like this, but perhaps more efficient,
was included in matplotlib. It's a useful thing to be able to do.

Regards, George.

···

On 07/02/07, Michael Lerner <mglerner@...287...> wrote:

That works for me. Thanks. I was trying to muck around with _lut
directly and make a sentinel version of LinearSegmentedColormap. As I
didn't really know what I was doing, I was having some strange
results. Also, in case other folks don't realize this, you can
initialize this with a Colormap, LinearSegmentedColormap, etc.

I'd be happy to update the SciPy wiki.