Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

3d surface animation

I want to make a double slit wave animation with plotly. The project below makes only one image. I have googled a lot but I cannot find the exact format of the few lines that I guess are necessary to make it an animation (tried something with frames…).
Any advice?

Poul Riis
Denmark

import plotly.graph_objs as go

import numpy as np

xp = np.linspace(0, 200, 401,endpoint=True)
yp = np.linspace(-100, 100, 401,endpoint=True)
tarray = np.linspace(0, 1, 11,endpoint=True)
xGrid, yGrid = np.meshgrid(xp, yp)

d=80
lambd=10
T=1
A=0.02
twopi=2*np.pi
k=twopi/lambd
dh=d/2

omega=twopi/T

x =yGrid # x = r*cos(s)sin(t)
y = xGrid # y = r
sin(s)*sin(t)

def zz(t):
return A*(np.sin(np.sqrt(yGrid**2+(xGrid-dh)2)k-omegat)+np.sin(np.sqrt(yGrid2+(xGrid+dh)**2)k-omegat))

z=zz(0.1)

surface = go.Surface(x=x, y=y, z=z)
data = [surface]

layout = go.Layout(
title=‘Parametric Plot’,
scene=dict(
xaxis=dict(
gridcolor=‘rgb(255, 255, 255)’,
zerolinecolor=‘rgb(255, 255, 255)’,
showbackground=True,
backgroundcolor=‘rgb(230, 230,230)’
),
yaxis=dict(
gridcolor=‘rgb(255, 255, 255)’,
zerolinecolor=‘rgb(255, 255, 255)’,
showbackground=True,
backgroundcolor=‘rgb(230, 230,230)’
),
zaxis=dict(
gridcolor=‘rgb(255, 255, 255)’,
zerolinecolor=‘rgb(255, 255, 255)’,
showbackground=True,
backgroundcolor=‘rgb(230, 230,230)’,
range = [-1,1]
),
)
)

#frames=[dict(data=[dict(x=x,y=y,z=zz(t))]) for t in tarray]

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename=‘3d surface’)

Hey @priis, your question belongs to the Category Python, not plotly2.0. Please change it to be answered by people working with Python Plotly.

Your code with a few new lines works offline, not online. Inspect a few examples here: https://plot.ly/python/animations/, https://plot.ly/python/heatmap-animation/ or here
https://plot.ly/python/filled-area-animation/.

Uncomment frames=, remove x=x, y=y from its definition (because data in frames contains only the updates for initial data, and x, y were set there) and define the dict fig as follows:

fig=dict(data=data, layout=layout, frames=frames)

To control animation, insert in layout the updatemenus as it is defined in the last link above. You can change the frame duration if you want a faster or a slower animation.

I couldn’t run your code because the function zz is lacking a few math operations.