contour: map extended ranges to "under" and "over" values #1022

Merged
merged 4 commits into from Jul 24, 2012

Projects

None yet

3 participants

@efiring
Member
efiring commented Jul 17, 2012

Contourf was handling the extend kwarg by mapping the extended
ranges directly into the 0-1 normal colormap range, so that
using set_under and set_over had no effect; after this change, the
extended ranges are mapped outside the 0-1 range (after applying
the norm) so that the colors established by the set_under and set_over
colormap methods are used. By default, these are the end values of
the colormap. The new behavior matches the existing contourf documentation.

Fixed a bug in which the legend support for extend options was using the
wrong names for the options.

@efiring efiring contour: map extended ranges to "under" and "over" values
Contourf was handling the extend kwarg by mapping the extended
ranges directly into the 0-1 normal colormap range, so that
using set_under and set_over had no effect.
The legend support for extend options was also using the
wrong names for the options.
44d7556
@satdobato

I would like to see a test code or example.

@WeatherGod WeatherGod and 1 other commented on an outdated diff Jul 21, 2012
lib/matplotlib/contour.py
if self.extend in ('both', 'min'):
- self.layers[0] = 0.5 * (self.vmin + self._levels[1])
+ self.layers[0] = -1e300
@WeatherGod
WeatherGod Jul 21, 2012 Member

I hate magic numbers like this. Maybe we could use np.INF and np.NINF?

@efiring
efiring Jul 21, 2012 Member

On 2012/07/20 5:20 PM, Benjamin Root wrote:

          if self.extend in ('both', 'min'):
  •            self.layers[0] = 0.5 \* (self.vmin + self._levels[1])
    
  •            self.layers[0] = -1e300
    

I hate magic numbers like this. Maybe we could use np.INF and np.NINF?

I thought of that, and may yet do so; but I wanted to get out a fix that
would work, and could not take time to test whether potentially
dangerous things like INF would cause trouble in practice. Note that mpl
has other somewhat arbitrary special numbers, because they make it work
most of the time.

efiring added some commits Jul 21, 2012
@efiring efiring contourf_demo: add a figure to illustrate extend options with cmap
Also removed "from pylab import *".
bca3321
@efiring efiring contourf: use np.inf instead of 1e300 for out-of-range color levels
Note that trying to simplify the code further by using np.inf a
few lines above, in self._levels, does not work; I'm not sure what
it breaks, but it definitely breaks something, probably in the
colorbar code.
72e1c6c
@efiring efiring update CHANGELOG, api_changes.rst for new handling of extend kwarg 0c347f3
@efiring efiring merged commit 967c15a into matplotlib:master Jul 24, 2012
@efiring efiring added a commit to efiring/matplotlib that referenced this pull request Aug 6, 2012
@efiring efiring update contour_hatching test images for change caused by #1022
Filled contours now use more of the available colormap range than
previously.
1bf4dde
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment