contourf() color mapping

Hi,

I'm having some trouble producing a filled contour how I want it.

Say I'm plotting data over the range [1.2, 20] using 15 level lines evenly spaced
over that interval. I'd like the min of that interval to map to the min of the color spectrum (say "jet" so dark blue)
and the max of that interval to map to the max of the spectrum (so red). It doesn't seem to work that way.
When I do filled contours, sometimes the low values are mapped to black or dark gray and
sometimes they're mapped to blue.

I always want the endpoints of the spectrum to map to the endpoints of the plotted values. Can this be done?
Any help is appreciated. Thanks.

- James

James Conners wrote:

Hi,

I'm having some trouble producing a filled contour how I want it.

Say I'm plotting data over the range [1.2, 20] using 15 level lines evenly spaced
over that interval. I'd like the min of that interval to map to the min of the color spectrum (say "jet" so dark blue)
and the max of that interval to map to the max of the spectrum (so red). It doesn't seem to work that way. When I do filled contours, sometimes the low values are mapped to black or dark gray and sometimes they're mapped to blue.

I always want the endpoints of the spectrum to map to the endpoints of the plotted values. Can this be done? Any help is appreciated. Thanks.

The root of the problem is a questionable choice I made in the _process_colors method of ContourSet; I will investigate either changing it, or making it an option. In the meantime, there is an easy workaround: just use the set_clim method of the ContourSet, or the pyplot.clim function. In ipython -pylab:

z = rand(10,10)
cs = contourf(z)
cb = colorbar()
cs.set_clim(cs.layers.min(), cs.layers.max())
draw()

The idea behind the present default choice for clim within contourf is that
the range of colors covers values from the lowest contour level to the highest; the color of a *layer* is then the color of the midpoint between its bounding levels. This has some logic to it (and is more consistent with pcolor and image color mapping), but I agree that it probably makes more sense to use the full color range by default; most often, this is likely to be what one wants, and for the exceptions one can always use set_clim.

Eric

···

- James

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Great. Just what I needed. I appreciate it.

- James

···

On Feb 2, 2010, at 1:56 PM, Eric Firing wrote:

James Conners wrote:

Hi,

I'm having some trouble producing a filled contour how I want it.

Say I'm plotting data over the range [1.2, 20] using 15 level lines evenly spaced
over that interval. I'd like the min of that interval to map to the min of the color spectrum (say "jet" so dark blue)
and the max of that interval to map to the max of the spectrum (so red). It doesn't seem to work that way.
When I do filled contours, sometimes the low values are mapped to black or dark gray and
sometimes they're mapped to blue.

I always want the endpoints of the spectrum to map to the endpoints of the plotted values. Can this be done?
Any help is appreciated. Thanks.

The root of the problem is a questionable choice I made in the
_process_colors method of ContourSet; I will investigate either changing
it, or making it an option. In the meantime, there is an easy
workaround: just use the set_clim method of the ContourSet, or the
pyplot.clim function. In ipython -pylab:

z = rand(10,10)
cs = contourf(z)
cb = colorbar()
cs.set_clim(cs.layers.min(), cs.layers.max())
draw()

The idea behind the present default choice for clim within contourf is that
the range of colors covers values from the lowest contour level to the
highest; the color of a *layer* is then the color of the midpoint
between its bounding levels. This has some logic to it (and is more
consistent with pcolor and image color mapping), but I agree that it
probably makes more sense to use the full color range by default; most
often, this is likely to be what one wants, and for the exceptions one
can always use set_clim.

Eric

- James

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users