首页 > 解决方案 > Choropleth 地图不显示

问题描述

在此处输入图像描述

我下面的代码没有显示预期的输出,如附图所示。我的代码遗漏了什么?

gjson=r'https://cocl.us/sanfran_geojson'
Sanfransisco=folium.Map(location=[37.77, -122.42], zoom_start=12, tiles='Mapbox Bright')
Sanfransisco.choropleth(
    geo_data=gjson,
    data=df,
    columns=['Neighbourhood','Count'],
    key_on='feature.properties.District',
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name='Crime rate in Sanfransisco'

文件“”,第 11 行 legend_name='Sanfransisco 的犯罪率' ^ SyntaxError:解析时出现意外 EOF

标签: pythonchoropleth

解决方案


您需要在函数上加上右括号。尝试这个:

Sanfransisco.choropleth(
    geo_data=gjson,
    data=df,
    columns=['Neighbourhood','Count'],
    key_on='feature.properties.District',
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name='Crime rate in Sanfransisco')

我们无法判断您的代码是否有任何其他问题,因为我们不知道您的 DataFrame 的形式。


推荐阅读