Dynamically change surface plot data

Note that in this case each time the dataset is transferred. (opposite to marching cubes plot)

In [1]:
import k3d
import numpy as np
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets
import time
plot = k3d.plot()

Nx = 264
Ny = 264
xmin,xmax = -3,3
ymin,ymax = 0,3
x = np.linspace(xmin,xmax,Nx)
y = np.linspace(ymin,ymax,Ny)
x,y = np.meshgrid(x,y,indexing='ij')
surface =  k3d.surface(np.sin(x**2+y**2),xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,\
                       color=int(np.random.randint(0, 0xFFFFFF, 1)[0]))

plot += surface
plot.camera_auto_fit = False
plot.grid_auto_fit = False
/Users/marcin/anaconda3/lib/python3.7/site-packages/traittypes/traittypes.py:101: UserWarning: Given trait value dtype "float64" does not match required type "float32". A coerced copy has been created.
  np.dtype(self.dtype).name))
In [2]:
surface.heights = (np.sin(x**2)+np.cos(y**3))
In [3]:
surface.color=0xff0000
In [4]:
@interact(phi=widgets.FloatSlider(value=0.,min=0,max=2*np.pi,step=0.1))
def g(phi):
    f = np.sin(x**2+y**2-phi)
    surface.heights = f
In [5]:
plot.display()
In [ ]:
%time data =  (np.sin(x**2)+np.cos(y**3))
In [ ]:
%time surface.heights = data+2
In [ ]: