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.

import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.cm as mcmap
import numpy as np

def show_cmap_rgb(cmap, axes):
    x = np.linspace(0, 1, 256)
    rgba = cmap(x)
    lines = []
    for (idx, color) in enumerate('rgb'):
        lines.extend(axes.plot(x, rgba[:, idx], ':', color=color))
    axes.set_xlim(0, 1)
    axes.set_ylim(-0.1, 1.1)
    return lines

fig = plt.figure()

axes_f = fig.add_subplot(2, 1, 1)
show_cmap_rgb(mcmap.gist_stern, axes_f)
axes_f.set_title('Forward')

axes_r = fig.add_subplot(2, 1, 2)
show_cmap_rgb(mcmap.gist_stern_r, axes_r)
axes_r.invert_xaxis()
axes_r.set_title('Reversed')

Attachment: cm.patch
Description: Binary data

Attachment: _cm.patch
Description: Binary data

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to