Surface plot animation

I’ve been trying to solve this my self for a while and did some research, but wasn’t able to find the answer.
I need to animate a 3D surface plot. I have a 3-dimentional array of data for u(x, y, t), so I want to plot u(x, y) for each t and then observe the animation. I found a work around that I don’t really like. Do you guys know is there a proper way of doing the same in plotly? Here is my solution:

from plotly.offline import iplot
import ipywidgets as widgets
import time
from IPython.display import display

fig = go.FigureWidget(layout = layout)
surface = fig.add_surface(x = solver.x, y = solver.y, z=solver.u[0].T, colorscale = ‘YlGnBu’)

fig.layout.scene.zaxis.range = [np.min(solver.u), np.max(solver.u)]
fig.layout.scene.yaxis.range = [solver.Y_START, solver.Y_END]
fig.layout.scene.xaxis.range = [solver.X_START, solver.X_END]

def set_surface(i=0):
surface.z = solver.u[i].T


for i in range(solver.J):

as you can see it will only work once when running the last loop.
solver is an atribute of my class with all the data inside.

Thanks in advance for your help!

Hi @danielgafni,

You could try controlling the animation with an ipywidget Play widget (See instead of the for loop.

I don’t know if there’s a plotly FigureWidget example that does this, but here’s an example notebook from the bqplot project that uses the Play button and a slider to animate a plot ( Your year_changed function would call your set_surface function.


Thank you for your answer!

I’ve already managed to find the solution, basically it’s the same thing you advised me to do.

Prorblem solved.