Hi everyone,
I’m working on a Plotly map that currently focuses on Africa and the Middle East. The map shows data for different countries, with bubble sizes proportional to the total count. I’d like to expand the map to include other countries from the Middle East that happen to be in Asia (UAE, Pakistan, etc), but I’m not sure how to adjust the scope
or other settings to do this. Any help? I’m using a scatter_geo plot.
This is what i currently have:
import openpyxl
import pandas as pd
import plotly.express as px
# Load the Excel file
file_path = "your_file.xlsx" # Replace with the path to your Excel file
wb = openpyxl.load_workbook(file_path)
sheet = wb.active
# Extract data from the Excel sheet
data = {"Country": [], "TPM": [], "RE": [], "NPI": [], "SA": [], "LM": []}
for row in sheet.iter_rows(min_row=2, values_only=True): # Assuming first row is header
data["Country"].append(row[0])
data["TPM"].append(row[1] if row[1] is not None else 0)
data["RE"].append(row[2] if row[2] is not None else 0)
data["NPI"].append(row[3] if row[3] is not None else 0)
data["SA"].append(row[4] if row[4] is not None else 0)
data["LM"].append(row[5] if row[5] is not None else 0)
# Convert to DataFrame
df = pd.DataFrame(data)
# Calculate the Total Headcount
df["Total"] = df[["TPM", "RE", "NPI", "SA", "LM"]].sum(axis=1)
# Create the Geomap with customized hover data
fig = px.scatter_geo(
df,
locations="Country",
locationmode="country names",
size="Total",
title="Headcount per Country",
projection="natural earth",
size_max=50,
hover_name="Country",
hover_data={
"TPM": True,
"RE": True,
"NPI": True,
"SA": True,
"LM": True,
"Total": True,
},
)
fig.update_layout(
title_text="Headcounts<br>(Bubble size proportional to total headcount)",
showlegend=False,
geo=dict(
showframe=False,
showcoastlines=False,
projection_type="mercator",
resolution=50,
scope="africa", # Current scope is set to Africa; how to include other regions?
landcolor="rgb(217, 217, 217)",
bgcolor="white",
countrycolor="white",
coastlinecolor="white",
),
)
fig.show()
edit: What i’m trying to accomplish is getting the map to look like this (with the bubbles of course):