I once had a similar issue. I solved it like this. It takes the minimum and
maximum of the data and returns a colormap: Zero: White, Positive values:
blue, Negative values: red.

def mxcmap(_min,_max):
        if _min >= 0 and _max >= 0:
            cdict = {'red': ((0.0, 1.0, 1.0),
                                        (1.0, 0.0, 0.0)),
                                'green': ((0.0, 1.0, 1.0),
                                        (1.0, 0.0, 0.0)),
                                'blue': ((0.0, 1.0, 1.0),
                                        (1.0, 1.0, 1.0))}
        elif _min <= 0 and _max <= 0:
            cdict = {'red': ((0.0, 1.0, 1.0),
                                        (1.0, 1.0, 1.0)),
                                'green': ((0.0, 0.0, 0.0),
                                        (1.0, 1.0, 1.0)),
                                'blue': ((0.0, 0.0, 0.0),
                                        (1.0, 1.0, 1.0))}
        else:
            full_red = 1
            full_blue = 1
            if -_min > _max:
                full_blue = -float(_max)/_min
            else:
                full_red = -float(_min)/_max
            zero = 0.5-((_max+_min)/2.)/(_max-_min)

            cdict = {'red': ((0.0, 1.0, 1.0),
                    (zero, 1.0, 1.0),
                    (1.0, 1-full_blue, 1-full_blue)),
            'green': ((0.0, 1-full_red, 1-full_red),
                    (zero, 1.0, 1.0),
                    (1.0, 1-full_blue, 1-full_blue)),
            'blue': ((0.0, 1-full_red, 1-full_red),
                    (zero,1.0, 1.0),
                    (1.0, 1.0, 1.0))}
        return
pylab.matplotlib.colors.LinearSegmentedColormap('my_colormap',cdict,256)
-- 
View this message in context: 
http://old.nabble.com/Making-a-data-driven-colormap-tp28050311p28067995.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to