# question about levels & colormaps for contour functions

Pablo Romero wrote:

Eric,
I believe the problem is that my 19 levels are not evenly distributed;
Lv=(1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)

No, I don't think that has much to do with it, unless the problem is that the colors of some levels are too similar.

Again, please make a simple, complete, self-contained example, and we will go from there.

I think what you want may be something like this:

levs=[1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75]
norm = mpl.colors.BoundaryNorm(levs, 256)
z = rand(10,15)*14 # fake data covering only lower levs
contourf(z, levs, norm=norm, cmap=cm.jet, extend='both')
colorbar()

the first part of the range starts at 1,3,5, but then includes 6,7,8,9, and then only goes with even numbers..10,12,14,16,18,20...then by 5 up until 35, then jumps by 10...etc.
I know this seems strange, but this was done because Im plotting 'ocean wave heights' and these were decided to be the 'heights of interest' for the project Im working on.

Perfectly reasonable.

···

anyway, what I want is to be able to breakup the 'cm.jet' spectrum evenly based on the # of levels (and not on their values), and spread my levels evenly across the spectrum....
i.e., I want the first 6-7 levels to be evenly spread from blue to about green acros cm.jet's spectrum, approx. the next 6 levels to be evenly spread across cm.jet's yellow-orange part of the spectrum, and the last few levels to be evenly spread across the reds...
Ideally, Id like to be able to use any colormap, and simply break up its color spectrum evenly, and then assign each distinct color to each level in my levels array.
So, I guess I need a method to programatically, evenly break up cm.jet by the # of levels, create a colors array & pass this array to contourf(colors='mycolorsarray')...
does this make sense?
P.Romero

----------------------------------------

Date: Sun, 15 Mar 2009 08:32:32 -1000
From: efiring@...202...
Subject: Re: [Matplotlib-users] question about levels & colormaps for contour functions
To: romero619@...32...
CC: matplotlib-users@lists.sourceforge.net

Pablo Romero wrote:

Hi,

I would like to know how I can pass an array of levels and also a colormap to the contour() function and have the levels span the entire colormap. example...

if I do the following....

Lv=(1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)

cs=plt.contourf(X,Y,waveheight,Lv,cmap=cm.jet,extend='both')

I would expect that contours that are in the higher levels (i.e., levels above value '14' in my levels array) would be plotted with lighter colors in the cm.jet spectrum; the greens, yellows,oranges,reds, etc.

However, contourf is simply breaking up the lower,"dark blue" half of the cm.jet spectrum into small slices, and spreading all of my levels throughout only the bottom half of cm.jet.

I don't see the problem yet. Here is an attempt to recreate what it
sounds like you are describing above (run in ipython -pylab):

contourf(rand(10,12), arange(0,5.01,0.2), cmap=cm.jet, extend='both')
colorbar()

The data are all blue because they are in the 0-1 range, while the
levels span the 0-5 range. The colorbar shows that the colormap is
covering the latter range, as it should.

If you can make a simple self-contained example like this, and then
describe the difference between what it does and what you want it to do,
we can figure out how to get your desired result.

Eric

I followed this tutorial:
http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations

that shows how to create a "discrete" colormap, but this also didnt work; the contourf function again simply sliced up the lower, blue colors and spread my all of my layers across the "blues" in my discrete colormap.

If I use a colors array instead of a colormap, I can achieve what I want. However, Id like to be able to use a colormap so that I dont have to manually create color arrays everytime that I want to change my colorscheme.

So, how can I force contour() to spread my levels across THE WHOLE spectrum of a colormap?

Thanks,
P.Romero

_________________________________________________________________
Express your personality in color! Preview and select themes for Hotmail®.
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

_________________________________________________________________
Windows Live™ Contacts: Organize your contact list. http://windowslive.com/connect/post/marcusatmicrosoft.spaces.live.com-Blog-cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009

Eric,
the "BoundaryNorm" was what I was looking for.
it did exactly what I needed; split the colormap up evenly into discrete colors based on the number of elements in my levels array.

Thanks,
P.Romero

···

----------------------------------------

Date: Sun, 15 Mar 2009 10:38:22 -1000
From: efiring@...202...
Subject: Re: [Matplotlib-users] question about levels & colormaps for contour functions
To: romero619@...32...; matplotlib-users@lists.sourceforge.net

Pablo Romero wrote:

Eric,

I believe the problem is that my 19 levels are not evenly distributed;

Lv=(1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)

No, I don't think that has much to do with it, unless the problem is
that the colors of some levels are too similar.

Again, please make a simple, complete, self-contained example, and we
will go from there.

I think what you want may be something like this:

levs=[1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75]
norm = mpl.colors.BoundaryNorm(levs, 256)
z = rand(10,15)*14 # fake data covering only lower levs
contourf(z, levs, norm=norm, cmap=cm.jet, extend='both')
colorbar()

the first part of the range starts at 1,3,5, but then includes 6,7,8,9, and then only goes with even numbers..10,12,14,16,18,20...then by 5 up until 35, then jumps by 10...etc.

I know this seems strange, but this was done because Im plotting 'ocean wave heights' and these were decided to be the 'heights of interest' for the project Im working on.

Perfectly reasonable.

anyway, what I want is to be able to breakup the 'cm.jet' spectrum evenly based on the # of levels (and not on their values), and spread my levels evenly across the spectrum....

i.e., I want the first 6-7 levels to be evenly spread from blue to about green acros cm.jet's spectrum, approx. the next 6 levels to be evenly spread across cm.jet's yellow-orange part of the spectrum, and the last few levels to be evenly spread across the reds...

Ideally, Id like to be able to use any colormap, and simply break up its color spectrum evenly, and then assign each distinct color to each level in my levels array.

So, I guess I need a method to programatically, evenly break up cm.jet by the # of levels, create a colors array & pass this array to contourf(colors='mycolorsarray')...

does this make sense?

P.Romero

----------------------------------------

Date: Sun, 15 Mar 2009 08:32:32 -1000
From: efiring@...202...
Subject: Re: [Matplotlib-users] question about levels & colormaps for contour functions
To: romero619@...32...
CC: matplotlib-users@lists.sourceforge.net

Pablo Romero wrote:

Hi,

I would like to know how I can pass an array of levels and also a colormap to the contour() function and have the levels span the entire colormap. example...

if I do the following....

Lv=(1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)

cs=plt.contourf(X,Y,waveheight,Lv,cmap=cm.jet,extend='both')

I would expect that contours that are in the higher levels (i.e., levels above value '14' in my levels array) would be plotted with lighter colors in the cm.jet spectrum; the greens, yellows,oranges,reds, etc.

However, contourf is simply breaking up the lower,"dark blue" half of the cm.jet spectrum into small slices, and spreading all of my levels throughout only the bottom half of cm.jet.

I don't see the problem yet. Here is an attempt to recreate what it
sounds like you are describing above (run in ipython -pylab):

contourf(rand(10,12), arange(0,5.01,0.2), cmap=cm.jet, extend='both')
colorbar()

The data are all blue because they are in the 0-1 range, while the
levels span the 0-5 range. The colorbar shows that the colormap is
covering the latter range, as it should.

If you can make a simple self-contained example like this, and then
describe the difference between what it does and what you want it to do,
we can figure out how to get your desired result.

Eric

I followed this tutorial:
http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations

that shows how to create a "discrete" colormap, but this also didnt work; the contourf function again simply sliced up the lower, blue colors and spread my all of my layers across the "blues" in my discrete colormap.

If I use a colors array instead of a colormap, I can achieve what I want. However, Id like to be able to use a colormap so that I dont have to manually create color arrays everytime that I want to change my colorscheme.

So, how can I force contour() to spread my levels across THE WHOLE spectrum of a colormap?

Thanks,
P.Romero

_________________________________________________________________
Express your personality in color! Preview and select themes for Hotmail®.
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.