Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4c91abc

Browse files
made moving-point-on-a-curve faster
proposed by empet on the forum
1 parent f2f945b commit 4c91abc

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

‎doc/python/animations.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ fig.show()
145145

146146
```python
147147
import plotly.graph_objects as go
148-
149148
import numpy as np
150-
151149
# Generate curve data
152150
t = np.linspace(-1, 1, 100)
153151
x = t + t ** 2
@@ -156,7 +154,7 @@ xm = np.min(x) - 1.5
156154
xM = np.max(x) + 1.5
157155
ym = np.min(y) - 1.5
158156
yM = np.max(y) + 1.5
159-
N = 50
157+
N = 25
160158
s = np.linspace(-1, 1, N)
161159
xx = s + s ** 2
162160
yy = 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

191192
fig.show()
192193
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /