I am trying to create a choropleth map using plotly and mapbox similar to the US map https://plot.ly/python/mapbox-county-choropleth/ but of African countries.
(我正在尝试使用plotly和mapbox创建类似于美国地图https://plot.ly/python/mapbox-county-choropleth/的非洲地区的地图。)
I am new to Python and coding period, so I am a bit lost. (我是Python和编码阶段的新手,所以我有点迷路。)
My geo data json doesn't have the 'id' field like the the Plotly example. (我的地理数据json没有“ Plotly”示例那样的“ id”字段。)
Do I need to create one? (我需要创建一个吗?)
Or do I need to just index by df by country? (还是只需要按国家/地区按df索引?)
But then how do I match up the instances in the json file? (但是,我该如何匹配json文件中的实例?)
Any help would be appreciated (任何帮助,将不胜感激)
with open('custom.geo.json') as response:
africa_geo = json.load(response)
data=pd.read_csv('africa_project.csv')
africa_geo['features'][0]
{'type': 'Feature',
'properties': {'scalerank': 0,
'featurecla': 'Admin-0 country',
'labelrank': 3,
'sovereignt': 'Burkina Faso',
'sov_a3': 'BFA',
'adm0_dif': 0,
'level': 2,
'type': 'Sovereign country',
'admin': 'Burkina Faso',
'adm0_a3': 'BFA',
'geou_dif': 0,
'geounit': 'Burkina Faso',
'gu_a3': 'BFA',
'su_dif': 0,
'subunit': 'Burkina Faso',
'su_a3': 'BFA',
'brk_diff': 0,
'name': 'Burkina Faso',
'name_long': 'Burkina Faso',
'brk_a3': 'BFA',
'brk_name': 'Burkina Faso',
'brk_group': None,
'abbrev': 'B.F.',
'postal': 'BF',
'formal_en': 'Burkina Faso',
'formal_fr': None,
'note_adm0': None,
'note_brk': None,
'name_sort': 'Burkina Faso',
'name_alt': None,
'mapcolor7': 2,
'mapcolor8': 1,
'mapcolor9': 5,
'mapcolor13': 11,
'pop_est': 15746232,
'gdp_md_est': 17820,
'pop_year': -99,
'lastcensus': 2006,
'gdp_year': -99,
'economy': '7. Least developed region',
'income_grp': '5. Low income',
'wikipedia': -99,
'fips_10_': 'UV',
'iso_a2': 'BF',
'iso_a3': 'BFA',
'iso_n3': '854',
'un_a3': '854',
'wb_a2': 'BF',
'wb_a3': 'BFA',
'woe_id': 23424978,
'woe_id_eh': 23424978,
'woe_note': 'Exact WOE match as country',
'adm0_a3_is': 'BFA',
'adm0_a3_us': 'BFA',
'adm0_a3_un': -99,
'adm0_a3_wb': -99,
'continent': 'Africa',
'region_un': 'Africa',
'subregion': 'Western Africa',
'region_wb': 'Sub-Saharan Africa',
'name_len': 12,
'long_len': 12,
'abbrev_len': 4,
'tiny': -99,
'homepart': 1,
'filename': 'BFA.geojson'},
'geometry': {'type': 'Polygon',
'coordinates': [[[-0.3976712649999, 15.002134501000072],
[-0.361471923999943, 15.017740784000113],
[-0.29917598499992, 15.054741110000064],
[-0.236699177999867, 15.065618999000035],
[-0.166987670999902, 15.049676819000098],
[-0.033404092999916, 14.995933329000096],
[-0.033197387999962, 14.995933329000096],
[0.218466838000012, 14.910977275000109],
[0.22084395400006, 14.888213806000126],
[0.211852254000121, 14.874803772000078],
...]]}}
fig = go.Figure(go.Choroplethmapbox(geojson=africa_geo, locations=data.country_name, z=data.ranking,
colorscale="Viridis"))
fig.update_layout(mapbox_style="dark", mapbox_accesstoken=token,
mapbox_zoom=1, mapbox_center = {"lat": 6.6111, "lon": 20.9394})
fig.show()
ask by Viktor Avdulov translate from so