[英]How to label animation frame in plotly express?
我在 python 中使用 plotly express
我有一个 px.choropleth 人物,其中 slider 使用 animation_frame
animation 帧的 label 当前为 animation_frame=
我想将其更改为“年”
如何更改animation_frame的label?
简单的回答:
fig.update_layout(sliders=[{"currentvalue": {"prefix": "Year="}}])
import io, requests
import plotly.express as px
import pandas as pd
dfraw = pd.read_csv(
io.StringIO(
requests.get(
"https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/vaccinations/vaccinations.csv"
).text
)
)
dfraw["date"] = pd.to_datetime(dfraw["date"])
df = (
dfraw.assign(year=lambda d: d["date"].dt.year)
.groupby(["iso_code", "year"], as_index=False)
.agg({"date": "last", "people_fully_vaccinated": "last"})
).sort_values(["year","iso_code"])
fig = px.choropleth(
df, locations="iso_code", color="people_fully_vaccinated", animation_frame="year"
)
fig.update_layout(sliders=[{"currentvalue": {"prefix": "Year="}}])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.