我在用folium
创建一组国家的等值区域地图。我正在关注文档 http://folium.readthedocs.org/en/latest/#choropleth-examples。然而。由于某种原因,地图没有显示任何阴影。我正在使用来自自然地球的世界 geojson(请参阅gist https://gist.github.com/prithwi/d029b239b7f1de7a895e).
我的数据框看起来像:
>>> spatial_scores.head()
Out[1]:
id Country Score
PER Peru 2.810300
HND Honduras 2.734521
GUF French Guiana 2.730886
SLV El Salvador 2.473134
CRI Costa Rica 2.454963
世界 geojson 看起来像:
>>> world_json['features'][0]['id']
Out [2]:
u'AFG'
分区统计图代码的相关部分如下:
map1 = folium.Map(location=[-15., -60], zoom_start=4)
map1.geo_json(geo_path=world_json_path,
data_out='data.json',
data=spatial_scores,
columns=['id', 'Score'],
threshold_scale=[0, 1, 2, 3, 4],
key_on='features.id',
fill_color='BuPu', fill_opacity=0.7, line_opacity=0.5,
legend_name='Score')
map1.create_map('./Scores.html')
However, am not getting any choropleth result and left with just the base country map as below
我做错了什么吗?
[Edit]
我解决了这个问题。绘制choropleth
我只需要将这些键保留在geojson
这也在我的数据框中。
merged = gdf.merge(spatial_scores, left_on='name', right_on='Country')
spatial_gdf = gpd.GeoDataFrame(merged.iloc[:, [0, 1]])
data_df = merged.iloc[:, [2, 3, 4]]