@@ -145,9 +145,7 @@ fig.show()
145
145
146
146
``` python
147
147
import plotly.graph_objects as go
148
-
149
148
import numpy as np
150
-
151
149
# Generate curve data
152
150
t = np.linspace(- 1 , 1 , 100 )
153
151
x = t + t ** 2
@@ -156,7 +154,7 @@ xm = np.min(x) - 1.5
156
154
xM = np.max(x) + 1.5
157
155
ym = np.min(y) - 1.5
158
156
yM = np.max(y) + 1.5
159
- N = 50
157
+ N = 25
160
158
s = np.linspace(- 1 , 1 , N)
161
159
xx = s + s ** 2
162
160
yy = s - s ** 2
@@ -167,26 +165,29 @@ fig = go.Figure(
167
165
data = [go.Scatter(x = x, y = y,
168
166
mode = " lines" ,
169
167
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 ,
174
172
xaxis = dict (range = [xm, xM], autorange = False , zeroline = False ),
175
173
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)])
190
191
191
192
fig.show()
192
193
```
0 commit comments