from ipyleaflet import (
Map,
Marker,
TileLayer,
ImageOverlay,
Polyline,
Polygon,
Rectangle,
Circle,
CircleMarker,
GeoJSON,
DrawControl,
)
center = [34.6252978589571, -77.34580993652344]
zoom = 10
m = Map(center=center, zoom=zoom)
m
import matplotlib as mpl
import matplotlib.cm
import matplotlib.colors
import numpy as np
def n_colors(n, colormap=mpl.cm.Blues):
data = np.linspace(0.0, 1.0, n)
c = [mpl.colors.rgb2hex(d[0:3]) for d in colormap(data)]
return c
def data_to_colors(data, colormap=mpl.cm.Blues):
c = [mpl.colors.rgb2hex(d[0:3]) for d in colormap(mpl.colors.Normalize()(data))]
return c
import json
with open("demo.json") as f:
data = json.load(f)
n_features = len(data["features"])
colors = n_colors(n_features)
print(n_features)
colors
for feature, color in zip(data["features"], colors):
feature["properties"]["style"] = {
"color": color,
"weight": 1,
"fillColor": color,
"fillOpacity": 0.5,
}
data["features"][0]
g = GeoJSON(data=data)
m.add(g)
# m.remove_layer(g)
# g.close()