数据可视化:Choropleth 地图不显示颜色

Data visualization: Choropleth map not displaying color

我刚开始使用数据可视化,现在我想创建一个等值线图来显示英超联赛中的足球比赛数量。

我使用 python 3.8.5 并在 CSV 文件中有一个数据集。我尝试使用 plotly 创建等值线图。之后,我创建了一个等值线,但我的问题是地图没有显示任何颜色,它只显示地球形式。

代码在这里:https://github.com/quockhanhcao/Question

import json
import pandas as pd
import plotly.express as px


country = json.load(open("countries.geojson", "r"))
df = pd.read_csv('forward_country.csv')
country_code_map = {}

#map the code in geojson file of each country in csv file
for feature in country['features']:
    feature['code'] = feature['properties']['ISO_A3']
    country_code_map[feature['properties']['ADMIN']] = feature['code']
df['code'] = df['Country'].apply(lambda x: country_code_map[x])


fig = px.choropleth(df, locations='code', geojson=country, color = 'Number')
fig.show()

我们需要link GeoJson的ISO_A3国家缩写名称。

from urllib.request import urlopen
import json
import pandas as pd
import plotly.express as px

with urlopen('https://raw.githubusercontent.com/quockhanhcao/Question/main/countries.geojson') as response:
    country = json.load(response)

# country = json.load(open("./data/countries.geojson", "r"))
df = pd.read_csv('./data/forward_country.csv')
country_code_map = {}

#map the code in geojson file of each country in csv file
for feature in country['features']:
    feature['code'] = feature['properties']['ISO_A3']
    country_code_map[feature['properties']['ADMIN']] = feature['code']
df['code'] = df['Country'].apply(lambda x: country_code_map[x])

fig = px.choropleth(df, geojson=country,
                    locations='code',
                    featureidkey="properties.ISO_A3",
                    color='Number')

fig.show()