如何将html
弹出框添加到Folium choropleth
映射?
我对Folium.CircleMarker
没有问题,但无法找到Choropleth地图的方法。
目前我的方法是:
import folium
import pandas as pd
m = folium.Map(location=[LAT, LONG], tiles = 'Stamen Terrain', zoom_start=8)
mm = folium.Choropleth(
geo_data=polygons,
name='Number of Points in Shape File',
data=df,
columns=['shape_name', 'number_of_points'],
key_on='feature.properties.shape_name',
fill_color='Greens',
highlight=True,
smooth_factor=0,
threshold_scale=[0, 2, 4, 6, 8, 10, 15, 20, 35, 50],
legend_name= 'Number of Points within Polygon').add_to(m)
当鼠标悬停在polygons
绘制的形状文件上时,添加工具提示的部分。
mm.geojson.add_child(folium.features.GeoJsonTooltip(
fields=['shape_name', 'number_of_points'],
aliases=['Polygon Name: ', 'Number of Points within Boundary: '],
style=('background-color: grey; color: white;')
))
我如何添加一个html弹出时,悬停在一个绘制的形状文件在Folium,例如合并图像?
将绘制的数据与PolyLine
特征叠加?
我在这篇文章中看到了Folium中choropleth弹出窗口的实现:如何提高你的Folium choropleth地图技能
我报告下面代码的一部分,而是学分原作者在上面的链接:
# Add hover functionality.
style_function = lambda x: {'fillColor': '#ffffff',
'color':'#000000',
'fillOpacity': 0.1,
'weight': 0.1}
highlight_function = lambda x: {'fillColor': '#000000',
'color':'#000000',
'fillOpacity': 0.50,
'weight': 0.1}
NIL = folium.features.GeoJson(
data = final_df,
style_function=style_function,
control=False,
highlight_function=highlight_function,
tooltip=folium.features.GeoJsonTooltip(
fields=['state','wills'],
aliases=['state','wills'],
style=("background-color: white; color: #333333; font-family: arial; font-size: 12px; padding: 10px;")
)
)
sample_map2.add_child(NIL)
sample_map2.keep_in_front(NIL)