I would like the percentage values to change as I move from year to year. Also, for some reason the value reading does not change eventhough it should be death rate per 100,000, instead of number of deaths.
decades = [1970, 1980, 1990, 2000, 2010]
cols = ['Number of Deaths', 'Death Rate Per 100,000']
per= ['Number of Deaths pct change', 'Death Rate Per 100,000 pct change']
figs = []
frames = []
for c, color, p in zip(cols, ["Blues", 'Reds'], per):
fig = px.choropleth(
data_frame=Global_Burden_of_Disease_df_country,
locations='Country Name',
locationmode='country names',
color=c,
hover_name="Country Name",
hover_data=p,
animation_frame="Year",
projection="equirectangular",
color_continuous_scale=color,
)
fig.update_layout(coloraxis_colorbar_title=c)
figs.append(fig)
for frame in fig.frames:
frame['name'] = f"{c}_{frame['name']}"
frames.append(frame)
layout = {
k: v
for k, v in figs[0].to_dict()["layout"].items()
if k not in ["template", "updatemenus"]
}
fig = go.Figure(data=figs[0].data, layout=layout)
fig.frames = frames
frames_dict = {c: [f for f in frames if f['name'].startswith(c)] for c in cols}
dropdown_buttons = [
{
"label": c,
"method": "animate",
"args": [
[f"{c}_{year}" for year in Global_Burden_of_Disease_df_country['Year'].unique()],
{
"mode": "immediate",
"frame": {"duration": 500, "redraw": True},
"transition": {"duration": 0},
}
],
}
for c in cols
]
fig.update_layout(
updatemenus=[
{
"buttons": dropdown_buttons,
"direction": "down",
"showactive": True,
}
],
coloraxis_colorbar_title=cols[0],
title={"text": f"World map of {cols[:]} in {decades}"},
)
fig.show()
I tried messing with my code, but it resulted in ther percentage hover name to remain at zero.
I am abit confused about how I would change the value reading name, as I am new to plotly.