Example #1
0
    def __init__(self, cbar, mapimage):
        self.cbar = cbar
        self.mapimage = mapimage
        self.press = None
        self.cycle = sorted([i for i in dir(plt.cm) if hasattr(getattr(plt.cm,i),'N')])

        self.index = self.cycle.index(ScalarMappable.get_cmap(cbar).name)
Example #2
0
def cmap_discretize(cmap, N):
    """Return a discrete colormap from the continuous colormap cmap.

       cmap: colormap instance, eg. cm.jet.
       N: number of colors.

       Example
       x = resize(arange(100), (5,100))
       djet = cmap_discretize(cm.jet, 5)
       imshow(x, cmap=djet)
    """
    if type(cmap) == str:
        cmap = ScalarMappable.get_cmap(cmap)
    colors_i = np.concatenate((np.linspace(0, 1., N), (0., 0., 0., 0.)))
    colors_rgba = cmap(colors_i)
    indices = np.linspace(0, 1., N + 1)
    cdict = {}
    for ki, key in enumerate(('red', 'green', 'blue')):
        cdict[key] = [(indices[i], colors_rgba[i-1,ki], colors_rgba[i,ki])\
                       for i in xrange(N+1)]
    # Return colormap object.
    return LinearSegmentedColormap(cmap.name + "_%d" % N, cdict, 1024)
Example #3
0
def cmap_discretize(cmap, N):
    """Return a discrete colormap from the continuous colormap cmap.

       cmap: colormap instance, eg. cm.jet.
       N: number of colors.

       Example
       x = resize(arange(100), (5,100))
       djet = cmap_discretize(cm.jet, 5)
       imshow(x, cmap=djet)
    """
    if type(cmap) == str:
        cmap = ScalarMappable.get_cmap(cmap)
    colors_i = np.concatenate((np.linspace(0, 1., N), (0.,0.,0.,0.)))
    colors_rgba = cmap(colors_i)
    indices = np.linspace(0, 1., N+1)
    cdict = {}
    for ki,key in enumerate(('red','green','blue')):
        cdict[key] = [(indices[i], colors_rgba[i-1,ki], colors_rgba[i,ki])\
                       for i in xrange(N+1)]
    # Return colormap object.
    return LinearSegmentedColormap(cmap.name + "_%d"%N, cdict, 1024)