🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Why does this 3d surface update slowly?

I am trying to create a plot that plots a series 3D surfaces, but that only shows the n’th surface when it is selected with a slider.

My plot works, but it is quite laggy, compared to the 2D plot animations from plotly. The 2D animations are very smooth, but these have a very noticable delay and lag (not just the plot update, but the update of the slider itself). Is this solvable, or are 3D plots with the option of sliding just always going to lag like this?

Here is my complete code, which I executed in jupyter notebook:

import plotly.express as px
import plotly.graph_objects as go
import numpy as np
import math


widths = (5,10,20,50,100)
depths = (1,5,10,50,100)

surfaces=[]
for step in range(0,20):
    z_values = []
    for width in widths:
        zs=[]
        for depth in depths:
            z = 15 - math.log(width) - math.log(depth) - math.log(step+1)
            zs.append(z)
        z_values.append(zs)
    surfaces.append(z_values)


fig = go.Figure()

for z_values in surfaces:
    fig.add_trace(go.Surface(
        x=widths,y=depths,z=z_values,
        visible =False,
        contours={'z':
                  dict(show=True, usecolormap=True,highlightcolor="limegreen",start=0,end=200,size=1)
                 }
    ))

fig.data[0].visible=True


steps=[]
for i,_ in enumerate(fig.data):
    visible =[False] * len(fig.data)
    visible[i]=True
    step = dict(method="update",
                args = [dict(visible = visible)]
               )
    steps.append(step)

sliders=[dict(active=0,currentvalue=dict(prefix="step: "), pad=dict(t=50),steps=steps)]    

fig.update_layout(dict(sliders=sliders,scene=dict(zaxis=dict(range=[0,20],autorange=False))))


fig.show()
fig.data[0].visible=False