如果你在第一个图上绘制等高线,你会发现等高线排列不正确。
你需要处理轮廓坐标,我建议使用
geojsoncontour
.
只需更改行后的代码
contourf_plot = ...
致:
import geojsoncontour
import branca
# Create geogson strings
geojson = geojsoncontour.contourf_to_geojson(
contourf=contourf_plot,
min_angle_deg=3.0,
ndigits=5,
stroke_width=1,
fill_opacity=0.7)
# Normalize iso values for colormap mapping
norm = Normalize(vmin=np.min(iso_values_filled), vmax=np.max(iso_values_filled))
# Covert float to hex colors
color_hex = []
for level in iso_values_filled:
color_hex.append( to_hex(plt.cm.viridis(norm(level))))
# Create a Folium map centered on the average latitude and longitude
center_lat, center_lon = np.mean(latitude), np.mean(longitude)
mymap_polygon = folium.Map(location=[center_lat, center_lon], zoom_start=8)
# Creat colormap
cm = branca.colormap.LinearColormap(color_hex)
# Add filled contour polygons as GeoJSON overlay with colored areas
folium.GeoJson(
geojson,
style_function=lambda x: {
'color': x['properties']['stroke'],
'weight': x['properties']['stroke-width'],
'fillColor': x['properties']['fill'],
'fillOpacity': 0.7,
}).add_to(mymap_polygon)
# Update color map
mymap_polygon.add_child(cm)
你会得到结果的
mymap_polygon
: