I'm using branca to create a custom color map to use in a folium map. I would like for the scale to display the decimal places from the index still, not round to a whole numbers, but I'm having a hard time figuring out how to do this. Below is a snippet of some of the code I'm using.
`
import folium
import branca.colormap as cm
def create_scale():
output_colormap = cm.StepColormap(["#ffffcc","#c7e9b4", "#7fcdbb", "#41b6c4","#2c7fb8","#253494"],
index= [0.0,
10.0,
30.0,
50.7,
69.8,
92.1,
100.0
],
vmin=0.0,
vmax=100.0)
return output_colormap
def style_function(feature,colormap,measure):
value = feature['properties'][measure]
if value is not None:
fill_color = colormap(value) # Convert color value to string
else:
fill_color = 'gray'
return {
'fillColor': fill_color,
'color': 'black',
'weight': 1,
'fillOpacity': 0.7
}
def create_map(measure):
colormap = create_scale()
map = folium.Map(location=[30, 0], zoom_start=2)
folium.GeoJson(
geojson_test,
name='geojson',
style_function=lambda feature: style_function(feature,colormap,measure)).add_to(map)
svg_style = '<style>svg#legend {background-color: GhostWhite;border-style: solid;border-width: 1px;}</style>'
map.get_root().header.add_child(folium.Element(svg_style))
colormap.add_to(map)
return map
Here is what I get when I run this on a a randomly generated geojson with random values assigned.
I have tried making sure the index is a float variable as well as searching for solutions form others, but have not yet found a solution to this issue.