地区分布图没有显示我想要的

问题描述 投票:0回答:1
threshold_scale = np.linspace(df_value_counts['Count'].min(),
                              df_value_counts['Count'].max(),
                              6, dtype=int)
threshold_scale = threshold_scale.tolist() 
threshold_scale[-1] = threshold_scale[-1] + 1 

sf_map.choropleth(
    geo_data=sf_geo,
    data=df_value_counts,
    columns=['Neighborhood', 'Count'],
    key_on='feature.properties.name',
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    threshold_scale=threshold_scale,
    legend_name='Crime Rate in San Francisco')
sf_map

我得到这样一个形象:enter image description here

但我需要有一个这样的形象:enter image description here

python json numpy folium
1个回答
1
投票

问题是key_on='feature.properties.name'

应该key_on='feature.properties.DISTRICT'

看看JSON文件,看看那里的纬度/经度坐标映射到。在世界地图例如,在它的JSON文件是“名”,但在圣fransico它是“DISCTRICT”

# download countries geojson file
!wget --quiet https://cocl.us/sanfran_geojson -O san_francisco_nh.json

print('GeoJSON file downloaded!')

sf_geo = r'san_francisco_nh.json'

sanfran_map.choropleth(
    geo_data=sf_geo,
    data=nh_countindex,
    columns=['Neighborhood','Count'],
    key_on='feature.properties.DISTRICT',
    fill_color='YlOrRd',
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name="Neighborhood Crime"
)

sanfran_map

san fransico choropleth map

© www.soinside.com 2019 - 2024. All rights reserved.