[PATCH] Discontinuous colormaps are reversed incorrectly

Hi, developers. I stumbled upon this when I noticed that gist_stern_r isn’t the reverse of gist_stern. As the attached script shows, the discontinuity in red is wrong, and green stays zero instead of ramping. The problem seems to be that when cm.revcmap() reverses a linear segment map spec (such as {‘red’: [(0, 0, 0), (0.5, 1, 1), (1, 1, 1)], …}), it doesn’t swap the second and third elements of each tuple—the color values facing in each direction. That makes no difference for continuous colormaps but distorts discontinuous maps such as gist_stern. I believe that the attached “cm.patch” file fixes the problem.

The other patch, “_cm.patch”, is only aesthetic after the above patch is applied. It changes an element of the gist_stern colormap spec that should have been unused but which caused the green channel to stay at zero with the old revcmap. With the patched revcmap, the changed element should not be used, but the colormap spec will look like most others with the second and third elements of the tuple being equal.

show_cmap_mirrored.py (633 Bytes)

cm.patch (546 Bytes)

_cm.patch (541 Bytes)

I can confirm the bug, but I have not tested the patch.

Ben Root

···

On Fri, Oct 1, 2010 at 8:59 PM, Stan West <stan.west@…595…> wrote:

Hi, developers. I stumbled upon this when I noticed that gist_stern_r isn’t the reverse of gist_stern. As the attached script shows, the discontinuity in red is wrong, and green stays zero instead of ramping. The problem seems to be that when cm.revcmap() reverses a linear segment map spec (such as {‘red’: [(0, 0, 0), (0.5, 1, 1), (1, 1, 1)], …}), it doesn’t swap the second and third elements of each tuple—the color values facing in each direction. That makes no difference for continuous colormaps but distorts discontinuous maps such as gist_stern. I believe that the attached “cm.patch” file fixes the problem.

The other patch, “_cm.patch”, is only aesthetic after the above patch is applied. It changes an element of the gist_stern colormap spec that should have been unused but which caused the green channel to stay at zero with the old revcmap. With the patched revcmap, the changed element should not be used, but the colormap spec will look like most others with the second and third elements of the tuple being equal.

Patches committed in 8725. Thank you.

Eric

···

On 10/01/2010 03:59 PM, Stan West wrote:

Hi, developers. I stumbled upon this when I noticed that gist_stern_r
isn't the reverse of gist_stern. As the attached script shows, the
discontinuity in red is wrong, and green stays zero instead of ramping.
The problem seems to be that when cm.revcmap() reverses a linear segment
map spec (such as {'red': [(0, 0, 0), (0.5, 1, 1), (1, 1, 1)], ...}), it
doesn't swap the second and third elements of each tuple—the color
values facing in each direction. That makes no difference for continuous
colormaps but distorts discontinuous maps such as gist_stern. I believe
that the attached "cm.patch" file fixes the problem.

The other patch, "_cm.patch", is only aesthetic after the above patch is
applied. It changes an element of the gist_stern colormap spec that
should have been unused but which caused the green channel to stay at
zero with the old revcmap. With the patched revcmap, the changed element
should not be used, but the colormap spec will look like most others
with the second and third elements of the tuple being equal.