我正在尝试为一个 plotly 3D 散点图制作动画,但滑块没有响应(请参见下面的代码)。 有人知道如何解决这个问题吗?
感谢和祝福! 基督教
import plotly.graph_objs as go
from plotly.subplots import make_subplots
import numpy as np
# Define the initial plot
x = MC1Array[0,:,0]
y = MC1Array[0,:,1]
z = MC1Array[0,:,2]
fig = go.Figure(data=[go.Scatter3d(x=x, y=y, z=z, mode='markers', marker=dict(size=2))])
# Add frames to the plot
frames = []
for t in range(np.shape(MC1Array[:,:,0])[0]):
x = MC1Array[t,:,0]
y = MC1Array[t,:,1]
z = MC1Array[t,:,2]
frame = go.Frame(data=[go.Scatter3d(x=x, y=y, z=z, mode='markers', name=f'{t+1}')])
frames.append(frame)
sliders=[dict(steps= [dict(method= 'animate',
args= [[ f'{k+1}'],
dict(mode= 'e',
frame= dict( duration=1000, redraw= True ),
transition=dict( duration= 0)
)
],
label=f'{k+1}'
) for k in range(np.shape(MC1Array[:,:,:])[0])],
transition= dict(duration= 30 ),
x=0,#slider starting position
y=0,
currentvalue=dict(font=dict(size=12),
prefix='Day: ',
visible=True,
xanchor= 'center'
),
len=1.0,
active=1) #slider length)
]
# Update the plot with the frames
fig.update(frames=frames)
fig.update_layout(sliders=sliders)
fig.update_scenes(xaxis_visible=False, yaxis_visible=False,zaxis_visible=False )
fig.show()
我尝试根据轨迹和帧来定义动画,但两者都不起作用。