Folium中的断言错误“如果此元素不在图形中,则无法呈现”

2024-10-01 07:50:14 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试使用Folium包映射下面的链接代码以生成坐标列表的聚集标记弹出窗口时,出现以下错误:

assert isinstance(figure,figure),('You cannot render this Element' “如果它不在图形中。”)

我的集群策略成功地运行了,没有任何错误。当我通过在一个单独的jupyter单元格中实际调用map名称来生成map时,我得到了一个错误。我想不出解决办法。你知道吗

返回带有点的CHOROPLETH映射的主方法

charterdropped.crs = sdshape.crs
charterdropped = charterdropped.to_crs(epsg='4326')
cjson = charterdropped.to_json()
mappo = folium.Map([37.7556, -122.4399], zoom_start = 7)

mappo.choropleth(
    geo_data=districtchanged,
    data=districtchanged,
    columns=['FIPS', '% Total Population: White Alone'],
    key_on='feature.properties.FIPS',
    legend_name='White people', 
    fill_color='YlGn',
    fill_opacity=0.4,
    highlight=True) 
points = folium.features.GeoJson(cjson)
mappo.add_child(points)


#Cluster Method

marker_cluster = MarkerCluster().add_to(mappo)
for each in charterdropped[0:len(charterdropped)].iterrows():
    folium.Marker(
            location=[each[1]['latitude'], each[1]['longitude']],
            popup=folium.Popup(
                            folium.IFrame(
                                html=each[1]['SCH_NAME'])


            ).add_to(marker_cluster))

Code


Tags: toaddmapdata错误cjsonfigureeach