Create own colormap using matplotlib and plot color scale

前端 未结 4 521
清歌不尽
清歌不尽 2020-11-22 14:18

I have the following problem, I want to create my own colormap (red-mix-violet-mix-blue) that maps to values between -2 and +2 and want to use it to color points in my plot.

4条回答
  •  不要未来只要你来
    2020-11-22 14:44

    If you want to automate the creating of a custom divergent colormap commonly used for surface plots, this module combined with @unutbu method worked well for me.

    def diverge_map(high=(0.565, 0.392, 0.173), low=(0.094, 0.310, 0.635)):
        '''
        low and high are colors that will be used for the two
        ends of the spectrum. they can be either color strings
        or rgb color tuples
        '''
        c = mcolors.ColorConverter().to_rgb
        if isinstance(low, basestring): low = c(low)
        if isinstance(high, basestring): high = c(high)
        return make_colormap([low, c('white'), 0.5, c('white'), high])
    

    The high and low values can be either string color names or rgb tuples. This is the result using the surface plot demo: enter image description here

提交回复
热议问题