等值线数据未显示在地图上

choropleth data not showing on map

我试图在没有任何运气的情况下将以下数据框绘制到等值线图上。色标会反映出来,但不会绘制在地图上。任何建议表示赞赏。

df_map

country main_discipline amount  num_month
0   Albania 6   44300.00    81.0
1   Argentina   14  100000.00   135.0
2   Armenia 12  397140.00   234.0
3   Australia   908 476319.00   5826.0
4   Austria 297 13318464.01 3033.0
5   Bahamas 3   0.00    12.0
6   Barbados    1   0.00    25.0
7   Belarus 18  519730.00   286.0
8   Belgium 200 785907.04   2057.0
9   Benin   1   0.00    12.0

fig = go.Figure(data = go.Choropleth(
    locations = df_map.country,
    z = df_map.amount,
    text = df_map.country,
    colorscale = 'Blues',
))
fig.show()

为了在等值线图中指定一个位置,您不能使用国家名称,您需要一个三个字母的国家名称,相当于 ISO-3。我通过从 official reference.

中的数据手动添加三个字母的国家/地区名称来创建代码
import pandas as pd
import numpy as np
import io

data = '''
country main_discipline amount num_month code
0 Albania 6 44300.00 81.0 ALB
1 Argentina 14 100000.00 135.0 ARG
2 Armenia 12 397140.00 234.0 ARM
3 Australia 908 476319.00 5826.0 AUS
4 Austria 297 13318464.01 3033.0 AUT
5 Bahamas 3 0.00 12.0 BHM
6 Barbados 1 0.00 25.0 BRB
7 Belarus 18 519730.00 286.0 BLR
8 Belgium 200 785907.04 2057.0 BEL
9 Benin 1 0.00 12.0 BEN
'''

df_map = pd.read_csv(io.StringIO(data), delim_whitespace=True)

import plotly.graph_objects as go

fig = go.Figure(data = go.Choropleth(
    locations = df_map['code'],
    z = df_map['amount'],
    text = df_map['country'],
    colorscale = 'Blues',
    autocolorscale=False,
    reversescale=True,
))

fig.update_layout(autosize=False,height=600,width=800)
fig.show()