I’m using plotly to make a choropleth map.
I would like to add text labels to the map using fig.add_scattergeo, but it’s borrowing the colormapping from the plot and it doesn’t look good. The text doesn’t contrast with the background color and it is difficult to read.
I would like to know if and how I can modify the text traces produced by fig.add_scattergeo to have better contrast.
Code:
# Create a choropleth map with state names
fig = px.choropleth(
top_sectors_empl,
locations="st", # Column with state names
locationmode="USA-states", # Set location mode for U.S. states
color="ds_state_sector_headcount", # Column with data to visualize
scope="usa", # Restrict to the U.S.
title="Highest Employing Sector by State", # Title for the map
color_continuous_scale="Viridis", # Color scale
# labels={"value": "Value"}, # Label for the legend
)
fig.update_coloraxes(
dict(
colorbar=dict(
title="Annual Salary",
)
)
)
fig.add_scattergeo(
locations=top_sectors_empl["st"],
locationmode="USA-states",
text=top_sectors_empl["short_sector"],
mode="text")
# Save the figure as an HTML file
fig.write_html("choropleth_map_empl.html")
os.system("open choropleth_map_empl.html")