Choropleth 非洲地图不显示某些国家和岛屿

Choropleth Africa map doesn’t show some countries and islands

我正在使用等值线绘制非洲大陆地图。然而,有些地区没有出现在地图上,即使各自的字母代码是正确的。例如,我有来自塞舌尔 (sov_a3="SYC")、毛里求斯 (sov_a3="MUS") 的数据,但地图缺少这些区域或未填充。

有什么我想念的吗?我没有看到用 Plotly 制作的完整非洲地图,我想知道参数 scope=“africa”

是否有问题

按照下面的地图代码及其现在的样子。

fig_map = go.Figure(px.choropleth(df_map,
                            locations='sov_a3', color=map_count_column,
                            hover_name='country', animation_frame="date_2weeks",
                            color_continuous_scale="algae",
                            range_color=[0, max(df_map['cum_counts'])],
                            labels={'cum_counts': 'Number of genomes'}
                            ))
    fig_map.update_layout(geo_scope="africa")

import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
import numpy as np

countries = 'TZA,ESH,COD,SOM,KEN,SDN,TCD,ZAF,LSO,ZWE,BWA,NAM,SEN,MLI,MRT,BEN,NER,NGA,CMR,TGO,GHA,CIV,GIN,GNB,LBR,SLE,BFA,CAF,COG,GAB,GNQ,ZMB,MWI,MOZ,SWZ,AGO,BDI,MDG,GMB,TUN,DZA,ERI,MAR,EGY,LBY,ETH,DJI,UGA,RWA,SSD'
names = "Tanzania,W. Sahara,Dem. Rep. Congo,Somalia,Kenya,Sudan,Chad,South Africa,Lesotho,Zimbabwe,Botswana,Namibia,Senegal,Mali,Mauritania,Benin,Niger,Nigeria,Cameroon,Togo,Ghana,Côte d'Ivoire,Guinea,Guinea-Bissau,Liberia,Sierra Leone,Burkina Faso,Central African Rep.,Congo,Gabon,Eq. Guinea,Zambia,Malawi,Mozambique,eSwatini,Angola,Burundi,Madagascar,Gambia,Tunisia,Algeria,Eritrea,Morocco,Egypt,Libya,Ethiopia,Djibouti,Uganda,Rwanda,S. Sudan"
# Seychelles (sov_a3="SYC"), Mauritius (sov_a3="MUS")
countries += ",SYC,MUS"
names += ",Seychelles,Mauritius"
map_count_column = "cum_counts"

# simulate implied dataframe in question
df_map = (
    pd.DataFrame({"sov_a3": countries.split(","),"country":names.split(",")})
    .merge(pd.DataFrame({"date_2weeks": list("ABC")}), how="cross")
    .assign(
        cum_counts=lambda d: np.random.randint(1, 5, len(d)),
    )
)

# go.Figure is spurious remove
fig_map = px.choropleth(
    df_map,
    locations="sov_a3",
    color=map_count_column,
    hover_name="country",
    animation_frame="date_2weeks",
    color_continuous_scale="algae",
    range_color=[0, max(df_map["cum_counts"])],
    labels={"cum_counts": "Number of genomes"},
)
fig_map.update_layout(geo_scope="africa")

  • 现在我在定义岛屿的地方使用不同的 geojson。然而,这是不完美的,因为我没有确保名称正确映射到 geojson
  • 这确实显示了毛里求斯
import requests
res = requests.get("https://raw.githubusercontent.com/codeforgermany/click_that_hood/main/public/data/africa.geojson")

# use out own geometry
fig_map = px.choropleth(
    df_map,
    geojson=res.json(),
    locations="country",
    featureidkey="properties.name",
    color=map_count_column,
    hover_name="country",
    animation_frame="date_2weeks",
    color_continuous_scale="algae",
    range_color=[0, max(df_map["cum_counts"])],
    labels={"cum_counts": "Number of genomes"},
)

fig_map.update_geos(fitbounds="locations")