首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >choropleth地图未显示

choropleth地图未显示
EN

Stack Overflow用户
提问于 2020-01-12 15:49:10
回答 1查看 1.5K关注 0票数 0

我是Python的数据科学新手,这是我在这里的第一个帮助请求(请提前为一些错误道歉)。需要您的支持,以获得为什么这个(简单的数据帧为基础的) choropleth地图没有显示。读了很多关于争论的讨论,然后我验证了所有主要的东西:地区名称和NAAM (在geojson中),都在str中,等等-但我仍然卡住了,我看不到地图(只有图例)。让我知道如果需要更多的信息,在下面你可以找到代码:

代码语言:javascript
复制
df_clo=dfrc.groupby(['District']).mean()
df_clo.reset_index(inplace=True)
df_clo=df_clo[['District','Rent']]
df_clo['District'] = df_clo['District'].str.upper()
df_clo

Out9

代码语言:javascript
复制
District    Rent
0   BINNENSTAD  1792.281250
1   NOORDOOST   1763.558824
2   OOST    1739.186047
3   ZUID    1562.142857
4   ZUIDWEST    1397.689655

10年内

代码语言:javascript
复制
latitude = 52.09083
longitude = 5.12222
print('The geograpical coordinate of Utrecht are {}, {}.'.format(latitude, longitude))# create map of Utrecht using latitude and longitude values
utrecht_geo = r'https://raw.githubusercontent.com/umbesallfi/Coursera_Capstone/master/wijk_.geojson'
# create a numpy array of length 6 and has linear spacing from the minium total immigration to the maximum total immigration
threshold_scale = np.linspace(df_clo['Rent'].min(),
                              df_clo['Rent'].max(),
                              6, dtype=int)
threshold_scale = threshold_scale.tolist() # change the numpy array to a list
threshold_scale[-1] = threshold_scale[-1] + 1 # make sure that the last value of the list is greater than the maximum immigration
# let Folium determine the scale.
map_utr = folium.Map(location=[latitude, longitude], zoom_start=2, tiles='Mapbox Bright')
map_utr.choropleth(
    geo_data=utrecht_geo,
    data=df_clo,
    columns=['District', 'Rent'],
    key_on='feature.properties.NAAM',
    threshold_scale=threshold_scale,
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name='Price in Utrecht by Wijk',
    reset=True
)
map_utr

EN

回答 1

Stack Overflow用户

发布于 2020-01-15 03:40:16

地区名称不会以大写字母存储在wijk_.geojson文件中。因此,删除此行应该就足够了:

代码语言:javascript
复制
df_clo['District'] = df_clo['District'].str.upper()

我的代码:

代码语言:javascript
复制
import folium
import pandas as pd
import numpy as np

m = folium.Map(location=[52.09083, 5.12222],
               zoom_start=12,
               control_scale=True)

df_clo = pd.DataFrame({'District':['Binnenstad','Noordoost','Oost','Zuid','Zuidwest'],
                       'Rent':[1792.281250,
                               1763.558824,
                               1739.186047,
                               1562.142857,
                               1397.689655]})

threshold_scale = np.linspace(df_clo['Rent'].min(),
                              df_clo['Rent'].max(),
                              6, dtype=int)
threshold_scale = threshold_scale.tolist() # change the numpy array to a list
threshold_scale[-1] = threshold_scale[-1] + 1 # make sure that the last value of the list is greater than the maximum immigration

utrecht_geo = 'wijk_.geojson'

folium.Choropleth(geo_data=utrecht_geo,
                  name='choropleth',
                  data=df_clo,
                  columns=['District', 'Rent'],
                  key_on='feature.properties.NAAM',
                  threshold_scale=threshold_scale,
                  fill_color='YlOrRd',
                  fill_opacity=0.7,
                  line_opacity=0.2,
                  legend_name='Price in Utrecht by Wijk',).add_to(m)

folium.LayerControl().add_to(m)

m

返回此映射:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59701933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档