如何向Folium choropleth地图添加html弹出窗口?
我在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的绘图shapefile上时添加工具提示的部分。
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;')
))当我将鼠标悬停在Folium中的某个绘图shapefile上时,如何添加html弹出窗口,例如用于合并图像?
是否将打印的数据与PolyLine功能叠加?
发布于 2021-12-03 09:48:15
我在Folium中看到了一个弹出式窗口的实现:How to step up your Folium Choropleth Map skills
我报告了以下代码的一部分,但上面的链接中的原创作者是致谢的:
# 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)https://stackoverflow.com/questions/69529950
复制相似问题