[英]How can I generate a line animation for the stocks data using plotly?
Hey I was trying to make an line animation for the stocks data built in plotly. So I tried this code below following https://plotly.com/python/animations/ but nothing shows.嘿,我试图为 plotly 中内置的股票数据创建一行 animation。所以我在https://plotly.com/python/animations/之后尝试了以下代码,但没有任何显示。
import plotly.express as px
df = px.data.stocks()
fig = px.line(df, x = 'date', y=df.columns[1:6], animation_frame = 'date')
fig.show()
what I intended to do was to make a line animation of the 6 company's stock price with respect to the date.我打算做的是将 6 家公司的股票价格与日期相关联,形成一条线 animation。 I'm totally new to plotly so this maybe a dumb question but I'd be grateful if you guys could help.
我是 plotly 的新手,所以这可能是一个愚蠢的问题,但如果你们能提供帮助,我将不胜感激。 Thank You!
谢谢你!
import plotly.express as px
import pandas as pd
df = px.data.stocks()
df["date"] = pd.to_datetime(df["date"])
fig = px.line(df, x = df["date"].dt.day, y=df.columns[1:6], animation_frame=df["date"].dt.strftime("%b-%Y"))
fig.update_layout(yaxis={"range":[0,df.iloc[:,1:6].max().max()]})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.