Plotly dash scatter map doesn’t display scatter points

Result

I have this dataframe

Paesi_principali,Value,iso_alpha
Stati Uniti,16.6,US
Italia,10.6,IT
Germania,5,DE
Messico,4.6,MX
India,4.2,IN
Francia,3.7,FR
Regno Unito,3.7,UK
Spagna,3.3,ES
Canada,3.1,CA
Grecia,3.1,GR

And the code is

 example_graph10 =  px.scatter_geo(facebook1, locations="iso_alpha",locationmode ="ISO-3", color="iso_alpha",
                         hover_name="Paesi_principali", size="Value",
                         projection="natural earth")

But it doesn’t render. Why?

Answer

  • two character codes do not identify countries
  • have sourced from OWID locations
  • joined 2 character codes to 3 character codes, removed duplicates and fixed UK
  • then a simple case of plotting
import io
import requests
import pandas as pd
import numpy as np
import plotly.express as px

facebook1 = pd.read_csv(io.StringIO("""Paesi_principali,Value,iso_alpha
Stati Uniti,16.6,US
Italia,10.6,IT
Germania,5,DE
Messico,4.6,MX
India,4.2,IN
Francia,3.7,FR
Regno Unito,3.7,UK
Spagna,3.3,ES
Canada,3.1,CA
Grecia,3.1,GR"""))

# get iso_code 3 chars for countries
dfloc = pd.read_html(
    "https://github.com/owid/covid-19-data/blob/master/public/data/vaccinations/locations.csv"
)[0]

# join and fix 2 character codes to 3 character codes
facebook1 = facebook1.merge(
    dfloc.assign(iso2=np.where(dfloc["iso_code"].eq("GBR"), "UK",dfloc["iso_code"].str[0:2])).loc[
        :, ["iso_code", "location", "iso2"]
    ],
    left_on="iso_alpha",
    right_on="iso2",
    how="inner",
).pipe(lambda d: d.loc[~d["iso_code"].isin(["EST","FRO","GRL","GRD","CAF"])])

px.scatter_geo(facebook1, locations="iso_code",locationmode ="ISO-3", color="iso_alpha",
                         hover_name="Paesi_principali", size="Value",
                         projection="natural earth")

enter image description here