python-visualization / branca

This library is a spinoff from folium, that would host the non-map-specific features.
https://python-visualization.github.io/branca/
MIT License
111 stars 63 forks source link

Issue with LinearColormap to_step method? #82

Closed nubianlachlan closed 3 years ago

nubianlachlan commented 3 years ago

Hi, I was trying to generate a step colour scale from a linear scale providing index but it seems that it generates one less colour:

test_data = [10, 12, 17, 25, 27, 29, 31, 54, 58, 59, 61, 69, 71, 72, 86, 87, 90, 91]

color = cm.LinearColormap(['red', 'green']).to_step(index=test_data)

for i, x in enumerate(test_data):
      print(str(x) + ' ' + color.rgb_hex_str(x))

Outcome:

10 #ff0000 - same 12 #ff0000 - same 17 #f80300 25 #e60c00 27 #cf1800 29 #c81b00 31 #c11f00 54 #a22e00 58 #6f4800 59 #664c00 61 #614f00 69 #4f5800 71 #415f00 72 #3c6100 86 #187400 87 #0d7900 90 #037e00 91 #008000

Is this a bug or am I missing something?

nubianlachlan commented 3 years ago

I realised that it's not a bug I just need a starting index if I want to assign colours to all values