3

I am trying to create a custom cmap for use in Python 3.5 using an array of levels and an array of colors.

The levels array is: levels = [-4, 0 ,0, .25, 1, 1.5, 2, 3, 4, 5, 6, 8]

and the colors are:

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)  
    ]

I've tried using info from this page Making a custom colormap using matplotlib in python

and subsequently

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))])

but still receive the following error.

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

Any help or a point in the right direction would be much appreciated. Thanks!

Community
  • 1
  • 1
Dustin C
  • 31
  • 1
  • 2
  • 2
    Please provide a [minimal working example](http://stackoverflow.com/help/mcve) – nicoguaro Sep 29 '16 at 21:50
  • 2
    The error message tells you that your list needs to provide values between x=0 and x=1. In your code `-4/vmax < 0`. So essentially that means that you need to normalize your range of `[vmin=-4, vmax=8]` into the interval `[0,1]`, e.g. by calculating `(x-vmin)/(vmax-vmin)`. – ImportanceOfBeingErnest Sep 29 '16 at 22:09

0 Answers0