I think this would be useful.
While you're at it, in the attached file I have a function "rescale_cmap" that effectively changes the autoscaling of the colormap to the data by allowing specification of the range limits - I find this useful. You might like to look at this to see if it's worth generalising your additions a little,

Gary

Reinier Heeres wrote:
Hi all,

I would like to propose the attached patch to be able to use a gamma
value for color maps. This will make it simple to make your color
scale more 'sensitive' at the bottom or at the top, as can be seen in
the attached example. This could in principle also be solved by adding
a gamma normalizer, but I think that applying it to a color map is
quite coming practice, so in this case the preferred way.

I'd also like to add a few extra color maps (at least one plain
blue-white-red and one with darker shades at the high and low ends, as
in the attachment). I also remember a particular one ('terrain') in a
measurement program called 'Igor' that would be nice.

Looking at _cm.py, I would guess that could be done a bit more
efficient than the current 5880 lines as well by just specifying a few
colors and using LinearSegmentedColormap.from_list(). Is it ok if I
try to refactor that?

Let me know what you think.

Cheers,
import numpy as np
from numpy import dstack, pi
import matplotlib.pyplot as plt
import types
import matplotlib.colors as colors
import matplotlib._cm as _cm
from scipy.ndimage import maximum_filter

def rescale_cmap(cmap_name, low=0.0, high=1.0, plot=False):
    '''
    Example 1:
    my_hsv = rescale_cmap('hsv', low = 0.5)     # equivalent scaling to 
cplot_like(blah, l_bias=0.33, int_exponent=0.0)
    Example 2:
    my_hsv = rescale_cmap(cm.hsv, low = 0.5)
    '''
    if type(cmap_name) == types.StringType:
        cmap = eval('_cm._%s_data' % cmap_name)
    else:
        cmap = eval('_cm._%s_data' % cmap_name.name)
    LUTSIZE = plt.rcParams['image.lut']
    r = np.array(cmap['red'])
    g = np.array(cmap['green'])
    b = np.array(cmap['blue'])
    range = high - low
    r[:,1:] = r[:,1:]*range+low
    g[:,1:] = g[:,1:]*range+low
    b[:,1:] = b[:,1:]*range+low
    _my_data = {'red':   tuple(map(tuple,r)),
                'green': tuple(map(tuple,g)),
                'blue':  tuple(map(tuple,b))
               }
    my_cmap = colors.LinearSegmentedColormap('my_hsv', _my_data, LUTSIZE)

    if plot:
        plt.figure()
        plt.plot(r[:,0], r[:,1], 'r', g[:,0], g[:,1], 'g', b[:,0], b[:,1], 'b', 
lw=3)
        plt.axis(ymin=-0.2, ymax=1.2)

    return my_cmap
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to