I\'m trying to plot radar data in folium, and I\'m almost there. I followed this example (Contour plot data (lat,lon,value) within boundaries and export GeoJSON) to get my data
Not an expert... I just started with folium and jupyter and had a similar problem but with lines. You say you have GeoJson and polygons and the color is included in the json I assume.
The style_function might help you to get what you want?
The example below is produced with this page: http://geojson.io/ All I had to do was a "mapping" with the style_function. It's also possible to use a self defined function, see: https://github.com/python-visualization/folium/blob/master/examples/Colormaps.ipynb
import folium
geoJsonData = {
"features": [
{
"geometry": {
"coordinates": [
[
12.98583984375,
56.70450561416937
],
[
14.589843749999998,
57.604221411628735
],
[
13.590087890625,
58.15331598640629
],
[
11.953125,
57.955674494979526
],
[
11.810302734375,
58.76250326278713
]
],
"type": "LineString"
},
"properties": {
"stroke": "#fc1717",
"stroke-opacity": 1,
"stroke-width": 2
},
"type": "Feature"
},
{
"geometry": {
"coordinates": [
[
14.9468994140625,
57.7569377956732
],
[
15.078735351562498,
58.06916140721414
],
[
15.4302978515625,
58.09820267068277
],
[
15.281982421875002,
58.318144965188246
],
[
15.4852294921875,
58.36427519285588
]
],
"type": "LineString"
},
"properties": {
"stroke": "#1f1a95",
"stroke-opacity": 1,
"stroke-width": 2
},
"type": "Feature"
}
],
"type": "FeatureCollection"
}
m = folium.Map(location=[ 56.7, 12.9], zoom_start=6)
folium.GeoJson(geoJsonData,
style_function=lambda x: {
'color' : x['properties']['stroke'],
'weight' : x['properties']['stroke-width'],
'opacity': 0.6,
'fillColor' : x['properties']['fill'],
}).add_to(m)
m
The folium source code on git hub includes several nice examples as well:
https://github.com/python-visualization/folium/tree/master/examples
Here you find the options to play with:
http://leafletjs.com/reference.html#path-options
Hope this brings you forward!