Hi, is there a way to add a select callout annotation to a choropleth map in Python with Plotly/Express and/or Dash? Using the Plotly Express built-in US map 2 letter State code, map coordinates, or otherwise?
I am looking to add a descriptive story callout element that points to a specific state. Similar to how this is possible with x-axis elements on a bar chart, like this (from Styling Plotly Express Figures | Python | Plotly):
fig.add_annotation( # add a text callout with arrow
text=ābelow target!ā, x=āFriā, y=400, arrowhead=1, showarrow=True
)
*Hereās my Plotly Express code currently that works great up until wanting to annotate the figure:
#Plot dataframe df as a choropleth map
fig = px.choropleth(df_map,
locations = āState_codeā,
color=āSeat changeā,
hover_name=āStateā, #column to add to hover information
hover_data={#determines what shows in hover text
āYearā, āSeat changeā,āApportionment populationā,
āNumber of representativesā,
āAverage persons per representativeā
},
labels={#replaces default labels by column name
āSeat_changeā: āSeat changeā
},
animation_frame=āYearā,
color_continuous_scale=āInfernoā,
locationmode=āUSA-statesā,
scope=āusaā,
range_color=(-5, 10),
title=āChange in Number of Seats in U.S. House of Representatives by State: 1910 to 2020ā,
height=600
)
#Can I add something like this to insert a text blob somewhere with an arrow pointing to California?
fig.add_annotation(#add text callout with arrow
text=āCalifornia saw significant increases in House seats over the first half of the 20th century, with massive early 1900s population growth including foreign immigrants, then more workers from other states following the Great Depression which lasted until the late 1930s, and again after World War II ended in 1945.ā, āState_codeā=āCAā, arrowhead=1, showarrow=True
)