I created a chloropleth plot as follows
fig = px.choropleth(
filtered,
geojson=ward_geojson,
locations="wardname",
featureidkey="properties.wardname",
color="num_health_workers",
hover_data=["population", "num_health_workers"],
projection="mercator",
color_continuous_scale="Greens", # ✅ Use Greens
range_color=(
filtered["num_health_workers"].min(),
filtered["num_health_workers"].max(),
), # Optional: set min/max scale
color_continuous_midpoint=filtered[
"num_health_workers"
].median(), # Optional: midpoint tweak
)
# Add custom hovertemplate for the choropleth map
fig.update_traces(
hovertemplate="<b>Ward:</b> %{location}<br>"
"<b>Population:</b> %{customdata[0]:,}<br>"
"<b>Health Workers:</b> %{customdata[1]:,}<extra></extra>",
customdata=filtered[["population", "num_health_workers"]].values,
)
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(
geo=dict(
scope="africa",
showland=True,
landcolor="whitesmoke",
showcountries=True,
),
margin={"r": 0, "t": 0, "l": 0, "b": 0},
)
# Facilities
facility_df = (
facility_locations[
facility_locations["facility_stationed"].isin(selected_facilities)
]
if selected_facilities
else pd.DataFrame()
)
if not facility_df.empty:
# Create a list to store the scatter traces for facilities
facility_traces = []
for index, row in facility_df.iterrows():
scatter_trace = (
px.scatter_geo(
pd.DataFrame([row]), # Create a DataFrame with the current facility
lat="lat",
lon="lon",
hover_name="facility_stationed",
)
.update_traces(
mode="markers",
marker=dict(size=10, color="black"),
hovertemplate="<b>%{hovertext}</b><extra></extra>",
)
.data[0]
)
facility_traces.append(scatter_trace)
# Add all facility traces to the figure at once
for trace in facility_traces:
fig.add_trace(trace)
The facilities are multiple, using the same central point, making each of the numerous selected facilities replace the other as a single point. I need to modify the plot to add points for each selected facility as a separate point in a cluster. Any suggestions?