没有得到正确的地图颜色代码

2024-04-24 03:26:38 发布

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

在我的原始帖子中,我试图创建我的地图时遇到了一个错误,但我想我成功地通过了。我确定我没有选择正确的key_on功能,但不确定为什么这不会显示正确的图像。请帮帮我! 我从这里拿到了我的文件http://adamw523.com/toronto-geojson/

我希望得到这样的东西。你知道吗

crime rate in san francisco

这就是我所尝试的

df_crime=pd.DataFrame(df.Neighbourhood)
df_crime['premisetype']=pd.DataFrame(df.premisetype)
df_crime['offence']=pd.DataFrame(df.offence)
df_crime['MCI']=pd.DataFrame(df.MCI) #major crime indicators e.g. Theft
df_crime['occurrencedate']=pd.DataFrame(df.occurrencedate)
df_crime['reporteddate']=pd.DataFrame(df.reporteddate)
df_crime['occurrencehour'] = df_crime.occurrencedate.dt.strftime('%H:%M')
df_crime['reportedyear'] = df_crime.reporteddate.dt.strftime('%Y')
df_crime['reportedmonth'] = df_crime.reporteddate.dt.strftime('%m')
df_crime['reportedday'] = df_crime.reporteddate.dt.strftime('%d')
df_crime['reportedhour'] = df_crime.reporteddate.dt.strftime('%H:%M')
df_crime['Lat']=pd.DataFrame(df.Lat)
df_crime['Long']=pd.DataFrame(df.Long)
df_crime.head()

我使用的坐标是:

多伦多=43.70011 多伦多长=-79.4163

我也有这个密码给我计数

df_crime1=df_crime.groupby('Neighbourhood').size().reset_index(name="Count")
world_geo = r'simple.geojson' # geojson file
# create map of Toronto using latitude and longitude values
map_toronto = folium.Map(location=[TORONTO_LAT,TORONTO_LONG ], zoom_start=10)

folium.Choropleth(geo_data=world_geo,
                  data=df_crime1, 
                  columns=['Neighbourhood', 'Count'],
                  key_on='feature.properties.DAUID',
                  fill_color='YlOrRd',
                  fill_opacity=0.7,
                  line_opacity=0.2,
                  legend_name='Crime Rate in Toronto'
                  ).add_to(map_toronto)

map_toronto

这是我得到的一张照片

crime rate in toronto


Tags: keyinmapdataframedfgeojsondtgeo
1条回答
网友
1楼 · 发布于 2024-04-24 03:26:38

我的问题是得到正确的答案。正确的冷使用方法如下。你知道吗


world_geo = r'simple.geojson' # geojson file

    # create a plain world map
world_map = folium.Map(location=[TORONTO_LAT,TORONTO_LONG ], zoom_start=10)

# generate choropleth map using the total immigration of each country to Canada from 1980 to 2013
folium.Choropleth(
    geo_data=world_geo,
    data=df_crime1, 
    columns=['Neighbourhood', 'Count'],
    key_on='feature.properties.FULLHOOD',
    fill_color='YlOrRd',
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name='Crime Rate in Toronto'
    ).add_to(world_map)

# display map

world_map

相关问题 更多 >