Hi Everyone, Iβm having an odd issue where my animations proceed okay and the slider seems to also move forward as desired, but when I stop it in some form (either pause or manipulate the slider) it shows the first value in my time array timesm as the current value regardless of where the slider is, and when I continue playing the animation always resets to the start before playing. I also occasionally see that current time value blink back to the first value occasionally while playing. How do I get the animation to play from wherever I stop it, and make sure that the current value reflects the actually location of the slider when stopped?
Hereβs the relevant section of my code, slightly simplified to remove things I am certain are unrelated (which to be fair isnβt much). Thanks!
mra = ['circle','square', 'diamond', 'circle','square', 'diamond','circle']
def make_scatter_one_frame(o, i, rea):
frame = []
for j in labset:
name = str(j)
osr = o[rea==j]
xa,ya,za = get_data_true(osr, timesm[i])
opac = alphaselect(-1*aa[j-1], ae[j-1], -1*timesm[i].value)
if opac>0:
scatter3d = go.Scatter3d(x=xa, y=ya, z=za,mode='markers',
marker=dict(size=sva[j-1],color=ca[j-1], symbol=mra[j-1], opacity=opac), name=name)
elif j == 3 or j==2 or j==6:
scatter3d = go.Scatter3d(x=xa, y=ya, z=za,mode='markers',
marker=dict(size=sva[j-1]*0.5,color=ca[j-1], symbol=mra[j-1]+'-open', opacity=1), name=name)
else:
scatter3d = go.Scatter3d(x=[], y=[], z=[],mode='markers',
marker=dict(size=sva[j-1],color=ca[j-1], symbol=mra[j-1]+'-open', opacity=opac), name=name)
frame.append(scatter3d)
return frame
def make_layout(o, i):
xa,ya,za = get_data_true(o, timesm[i])
xmx, ymx, zmx = np.max(xa),np.max(ya),np.max(za)
xmn, ymn, zmn = np.min(xa),np.min(ya),np.min(za)
dxl, dyl, dzl = 120-(xmx-xmn), 120-(ymx-ymn), 120-(zmx-zmn)
layout = go.Layout(scene=dict(xaxis=dict(range=[xmn-(dxl/2), xmx+(dxl/2)],tickmode='linear', tick0=0, dtick=20),
yaxis=dict(range=[ymn-(dyl/2), ymx+(dyl/2)],tickmode='linear', tick0=0, dtick=20),
zaxis=dict(range=[zmn-(dzl/2), zmx+(dzl/2)],tickmode='linear', tick0=0, dtick=20),
xaxis_title='X [pc]',yaxis_title='Y [pc]',zaxis_title='Z [pc]',
aspectmode='cube'),
sliders=sliders,
updatemenus=[dict(type="buttons",
buttons=[dict(label="Play",method="animate",
args=[None, dict(frame=dict(duration=100, redraw=True,
transition=dict(duration=300), fromcurrent=True,
mode='immediate'))]),
dict(label="Pause",method="animate",
args=[[None], dict(frame=dict(duration=0, redraw=False),
mode='immediate', transition=dict(duration=0))])])])
return layout
def make_frames(o, rea):
frames = []
for frame_id in range(len(timesm)):
frame_plots = make_scatter_one_frame(o, frame_id, rea)
frames.append(go.Frame(data=frame_plots,
name=f'frame{frame_id}',
layout=make_layout(o, frame_id)))
return frames
steps = [dict(method='animate',
args=[[f'frame{k}'],
dict(mode='immediate',
frame=dict(duration=300),
transition=dict(duration=0)
)
],
label="{}".format(timesm[k])
) for k in range(len(timesm))]
sliders = [
dict(
x=0.1,
y=0,
len=0.9,
pad=dict(b=10, t=50),
active=0,
steps=steps,
currentvalue=dict(font=dict(size=20), prefix="", visible=True, xanchor='right'),
transition=dict(easing="cubic-in-out", duration=100))
]
fig = go.Figure(data=make_scatter_one_frame(o, 0, regal),
layout=make_layout(o, 0),
frames=make_frames(o, regal))
fig.show()