@@ -145,9 +145,7 @@ fig.show()
145145
146146``` python
147147import plotly.graph_objects as go
148-
149148import numpy as np
150-
151149# Generate curve data
152150t = np.linspace(- 1 , 1 , 100 )
153151x = t + t ** 2
@@ -156,7 +154,7 @@ xm = np.min(x) - 1.5
156154xM = np.max(x) + 1.5
157155ym = np.min(y) - 1.5
158156yM = np.max(y) + 1.5
159- N = 50
157+ N = 25
160158s = np.linspace(- 1 , 1 , N)
161159xx = s + s ** 2
162160yy = s - s ** 2
@@ -167,26 +165,29 @@ fig = go.Figure(
167165 data = [go.Scatter(x = x, y = y,
168166 mode = " lines" ,
169167 line = dict (width = 2 , color = " blue" )),
170- go.Scatter(x = x , y = y ,
171- mode = " lines " ,
172- line = dict (width = 2 , color = " blue " ))],
173- layout = go.Layout(
168+ go.Scatter(x = [xx[ 0 ]] , y = [yy[ 0 ]] ,
169+ mode = " markers " ,
170+ marker = dict (color = " red " , size = 10 ))])
171+ fig.update_layout( width = 600 , height = 450 ,
174172 xaxis = dict (range = [xm, xM], autorange = False , zeroline = False ),
175173 yaxis = dict (range = [ym, yM], autorange = False , zeroline = False ),
176- title_text = " Kinematic Generation of a Planar Curve" , hovermode = " closest" ,
177- updatemenus = [dict (type = " buttons" ,
178- buttons = [dict (label = " Play" ,
179- method = " animate" ,
180- args = [None ])])]),
181- frames = [go.Frame(
182- data = [go.Scatter(
183- x = [xx[k]],
184- y = [yy[k]],
185- mode = " markers" ,
186- marker = dict (color = " red" , size = 10 ))])
187-
188- for k in range (N)]
189- )
174+ title_text = " Kinematic Generation of a Planar Curve" , title_x = 0.5 ,
175+ updatemenus = [dict (type = " buttons" ,
176+ buttons = [
177+ dict (
178+ args = [None , {" frame" : {" duration" : 10 , " redraw" : False },
179+ " fromcurrent" : True , " transition" : {" duration" : 10 }}],
180+ label = " Play" ,
181+ method = " animate" ,
182+
183+ )])])
184+
185+ fig.update(frames = [go.Frame(
186+ data = [go.Scatter(
187+ x = [xx[k]],
188+ y = [yy[k]])],
189+ traces = [1 ]) # fig.data[1] is updated by each frame
190+ for k in range (N)])
190191
191192fig.show()
192193```
0 commit comments