具有级别和颜色数组的自定义cmap

时间:2016-09-29 21:00:20

标签: python python-3.x matplotlib colormap

我正在尝试使用级别数组和颜色数组创建一个在Python 3.5中使用的自定义cmap。

水平数组是:levels = [-4, 0 ,0, .25, 1, 1.5, 2, 3, 4, 5, 6, 8]

,颜色是:

colors=[
(0,0,0),
(.8627,.8627, .8627),
(.5569,.4745,.7098),
(.0392,.0392, .6078),
(.2667,.9725,.8314),
(.3529,.8667,.3843),
(1,1,.3922),
(.8627,.0392,.0196),
(.6863,0,0),
(.9412, .4706,.7059),
(1,1,1),
    (.5686,.1765,.5882)  
    ]

我尝试过使用此页Making a custom colormap using matplotlib in python

中的信息

随后

vmax = 8.0

zdr = mpl.colors.LinearSegmentedColormap.from_list('mycmap', [(-4 / vmax, (0,0,0)), (0 / vmax, (.8627,.8627, .8627)), (0 / vmax, (.5569,.4745,.7098)), (.25 / vmax, (.0392,.0392, .6078)), 
                                               (1 / vmax, (.2667,.9725,.8314)), (1.5 / vmax, (.3529,.8667,.3843)), (2 / vmax, (1,1,.3922)), (3 / vmax, (.8627,.0392,.0196)), 
                                               (4 / vmax, (.6863,0,0)), (5 / vmax, (.9412, .4706,.7059)), (6 / vmax, (1,1,1)), (8 / vmax, (.5686,.1765,.5882))])

但仍会收到以下错误。

ValueError: data mapping points must start with x=0. and end with x=1

非常感谢任何帮助或正确方向的观点。谢谢!

0 个答案:

没有答案