Hello everyone,
I’m using plotly express for the choropleth map it offers and my first graph is what I wanted the legend look like (reference below)
However, I tried making another map with the same format and the legend doesn’t match to the map I made before but I can’t figure out why this is the case, I tried a couple things but nothing worked (reference to legend that I wish to fix below)
If it helps this is my code for the map that has my desired legend
fig = px.choropleth(
# locations, using dataframe column 'state_name' it somehow understands that idk, color highlights the important part
data_frame=df, locations="state_name",locationmode="USA-states", scope="usa",color=INSURED_VS_POP_COLUMN,
title="Percentage of Uninsured Population by State - 2020",
# when i hover i want to emphasize something/ make it bold (hover_name)
# i want to display certain data when i hover over something (hover_data)
hover_name=self.state_names, hover_data={'state_name': False,"uninsured_amt": True, "insured_amt": True, "population": True, INSURED_VS_POP_COLUMN: True},
# rename columns to something more meaningful
labels={"insured_amt": "Amount Of People Insured", "uninsured_amt": "Amount Of People Uninsured",
"population": "Number Of People Used For The Data",
INSURED_VS_POP_COLUMN: "Percentage Of State Uninsured",
})
fig.show()
and below is the code that isn’t showing the same type of legend the code above has
fig = px.choropleth(
data_frame=df,locations=STATE_ABREV_COLUMN,locationmode="USA-states", scope="usa",
color=PERCENT_OF_PPL_IN_POV_COLUMN,
title="Percentage of Poverty Population by State - 2020",
hover_name=self.state_names,
hover_data={STATE_ABREV_COLUMN: False},
labels={PERCENT_OF_PPL_IN_POV_COLUMN: "Percent Of People In Poverty"}
fig.show()
If anyone could help me understand what’s going on, or help me resolve this issue that would be amazing thank you!