Choropleth Africa map doesn't show some countries and islands

Hi everyone!

I’m plotting an African continent map using choropleth. However, some regions are not appearing on the map, even the respective alpha codes being correct. For example, I have data from Seychelles (sov_a3=SYC), Mauritius (sov_a3=MUS), and the map is missing these regions or is not filled.

There is something I’m missing? I didn’t see a complete Africa map made with Plotly and I’m wondering if there is some issue with the parameter scope=“africa”

Follow below the code for the map and how it looks now.

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

1 Like

hi @Joicy
welcome to the community. That’s a good question.

Can you confirm that there is data attached to Seychelles and Mauritius?

Hi @adamschroeder

Thank you for your reply. Yes, there is data attached. The same is happening with Djibouti, Comoros, Mayotte, and Reunion.

interesting. OK, can you please share the df_map data with us so we can try to replicate the map locally on our computer?

Yes, sure.

Hi @adamschroeder did you get some solution?

Hi @Joicy
The answer is in this post (“bumping the resolution to 50m should do the trick”). fig_map.update_layout(geo_scope="africa", geo_resolution=50)

If you want Seychelles to appear, you’ll have to change the scope to world.

Using your same data:

import pandas as pd
import as px

df_map = pd.read_csv("data.csv")

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

P.S. you don’t need graph_objects here.

1 Like

This question and solution are super helpful. As a follow-up, @adamschroeder is there a raw source of information or rule that’s used to determine continents’ scopes, if any, each country/nation shows up with on a Plotly Express choropleth? In other words, are these determined by ISO - International Organization for Standardization
or something like that?

My reason for asking is because I often work with diplomacy orgs and am careful about how I represent nations in their recognized status, associations, name labels, etc. So it would be useful to know if there are others besides Seychelles that would not show up with any scope besides world, i.e. that would not appear with the continent scopes ( “africa” | “asia” | “europe” | “north america” | “south america” )? :world_map:

A couple of answers here:

  1. If your use-case is very sensitive to geographies (e.g. diplomacy!) you should provide your own GeoJSON geometries that have the exact resolution and representation that you seek (for example to correctly display disputed areas, newer ISO codes etc)
  2. The built-in geometries have two different spatial resolutions and the default is the lower resolution which omits certain coastline details and unfortunately omits small (on a global scale!) states like islands and city-states like singapore. You can control the scaling factor as per the docs: Map configuration and styling with Python

The geometries used in the built-in maps are here for reference: plotly.js/dist/topojson at master · plotly/plotly.js · GitHub

I should stress again, though, if your use-case is sensitive to this sort of thing, and “diplomacy orgs” sounds very sensitive, then I strongly recommend not using the built-in geometries! :slight_smile:


Thank you for the information @nicolaskruchten

I forgot to answer this part of it. There is no ISO standard for geography as far as I know, given how fraught a topic this is. There is a standard for country codes but not the actual lines on the map. Plotly’s built-in maps are sourced every few years from as per our documentation on “cultural base maps”. We don’t update them very often, and we don’t adjudicate competing claims for control or anything.

1 Like