簡體   English   中英

label animation 車架在 plotly 中如何快遞?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM