【发布时间】:2023-03-08 18:21:02
【问题描述】:
尊敬的,
我可以用 plotly 的烛台制作图。 但是,在一个循环中,如何使这些图形不是一个在另一个之下,而是全部在一个图形中?创建动画效果。 请参阅我在 5 天前的窗口中绘制蜡烛的示例,依次遍历整个 DataFrame。
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
#df
#i Date AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume \
#0 2015-02-17 127.489998 128.880005 126.919998 127.830002 63152400
#1 2015-02-18 127.629997 128.779999 127.449997 128.720001 44891700
#....
for index, row in df.iterrows():
FiveDaysBlock = df.iloc[index:(index+5),]
fig = go.Figure(data=[go.Candlestick(
x=FiveDaysBlock['Date'],
open=FiveDaysBlock['AAPL.Open'], high=FiveDaysBlock['AAPL.High'],
low=FiveDaysBlock['AAPL.Low'], close=FiveDaysBlock['AAPL.Close']
)])
fig.update_layout(xaxis_rangeslider_visible=False)
fig.update_layout(autosize=False,width=700, height=250, margin=dict( l=1,r=1,b=20, t=20, pad=2 ) )
fig.update_xaxes(rangebreaks=[dict(bounds=["sat", "mon"])])
fig.show()
See how the figure is generated under the other
谢谢,
【问题讨论】:
-
你想让下一个 FiveDaysBlock 替换当前动画的每一步吗?
-
@DerekO 是的,我想要。