[英]Plotly: How to combine scatter and line plots using Plotly Express?
[英]How to animate line in scatter plot using plotly express?
考慮分散的官方示例 plot animation
import plotly.express as px
df = px.data.gapminder()
px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country",
log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])
這導致 plot 中的標記正在動畫化。 但是,我也想為連接線設置動畫,這是不可能直接實現的。 我嘗試更新fig.frames.data[n].mode=markers+lines
之類的frames
的mode
和marker
屬性,但仍然沒有成功。 有人可以讓我知道我哪里出錯了。
干杯,DD
如果您通過animate the connecting lines
表示連接,例如,上面示例中所有說明Asia
等的標記,那么將以下內容添加到您的代碼中將產生下面的 plot。
fig.for_each_trace(lambda t: t.update(mode = 'lines+markers'))
for fr in fig.frames:
for d in fr.data:
d.update(mode='markers+lines')
import plotly.express as px
df = px.data.gapminder()
fig = px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country",
log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90],
# mode = 'markers+lines'
height = 600, width = 1000
)
# lineas and markers on first display
fig.for_each_trace(lambda t: t.update(mode = 'lines+markers'))
# lineas and markers on animation frames
for fr in fig.frames:
for d in fr.data:
d.update(mode='markers+lines')
fig.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.