colorbar and set_under

Hi folks,

I have encountered a problem using colorbar and set_under with a color map that has only 32 colors. The downward arrow is not filled with the correct color. If 64 colors are used, the arrow is filled correctly. I actually want 8 colors.

The test code is essentially image_masked.py from the 0.90.0 examples.

if I use: palette = cm.get_cmap("gray", 64)
the plot is OK.
if I use: palette = cm.get_cmap("gray", 32)
it is not OK.

In both cases, the upper arrow is the correct color.

I am using matplotlib version 0.90.0.

Here is the complete code:
#!/usr/bin/env python
'''imshow with masked array input and out-of-range colors.

'''

from pylab import *
import matplotlib.numerix.ma as ma
import matplotlib.colors as colors

delta = 0.025
x = y = arange(-3.0, 3.0, delta)
X, Y = meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = 10 * (Z2-Z1) # difference of Gaussians

# Set up a colormap:
#palette = cm.gray # OK
palette = cm.get_cmap("gray",32) # Not OK
#palette = cm.get_cmap("gray",64) # OK
palette.set_over('r', 1.0)
palette.set_under('g', 1.0)
# Alternatively, we could use
# to make the bad region transparent. This is the default.
# If you comment out all the palette.set* lines, you will see
# all the defaults; under and over will be colored with the
# first and last colors in the palette, respectively.
Zm = ma.masked_where(Z > 1.2, Z)

# By setting vmin and vmax in the norm, we establish the
# range to which the regular palette color scale is applied.
# Anything above that range is colored based on palette.set_over, etc.

im = imshow(Zm, interpolation='bilinear',
cmap=palette,
norm = colors.Normalize(vmin = -1.0, vmax = 1.0, clip = False),
origin='lower', extent=[-3,3,-3,3])
# extend choices are "both", "min", "max" and "neither"
colorbar(im, extend='both', shrink=0.8)
show()

···

--
Ms. Carol A. Leger
SRI International Phone: (650) 859-4114
333 Ravenswood Avenue G-273
Menlo Park, CA 94025 e-mail: leger@...392...

Carol Leger wrote:

Hi folks,

I have encountered a problem using colorbar and set_under with a color map that has only 32 colors. The downward arrow is not filled with the correct color. If 64 colors are used, the arrow is filled correctly. I actually want 8 colors.

The test code is essentially image_masked.py from the 0.90.0 examples.

if I use: palette = cm.get_cmap("gray", 64)
the plot is OK.
if I use: palette = cm.get_cmap("gray", 32)
it is not OK.

In both cases, the upper arrow is the correct color.

I am using matplotlib version 0.90.0.

Carol,

It works for me even with 8 colors, using the svn version of mpl. There have been a lot of changes between 0.90.0 and the present svn trunk (including a heart transplant by Mike D.), but I would not have expected any changes that would change the behavior you describe. I can't think of any way a bug would have made a break point in behavior between 32 and 64 colors. I'm baffled.

Can you install and run the svn version? Or the latest release (which does not include the new heart)? I also tried the svn maintenance branch, which is virtually identical to the last release, and it works the same as the trunk.

Eric