Mesh

Mesh is a object which displays triangles in 3D. A scalar can be displayed on the mesh using a colormap.


In [1]:
from matplotlib.tri import Triangulation
import numpy as np
import k3d

# this code is a part of matplotlib trisurf3d_demo
n_radii = 8
n_angles = 36

radii = np.linspace(0.125, 1.0, n_radii, dtype=np.float32)
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False, dtype=np.float32)[..., np.newaxis]

x = np.append(np.float32(0), (radii*np.cos(angles)).flatten())
y = np.append(np.float32(0), (radii*np.sin(angles)).flatten())

z = np.sin(-x*y)
indices = Triangulation(x,y).triangles.astype(np.uint32)

plot = k3d.plot()
plot



In [2]:
plt_mesh = k3d.mesh(np.vstack([x,y,z]).T, indices,
                   color_map = k3d.colormaps.basic_color_maps.Jet, 
                   attribute=z,
                   color_range = [-1.1,2.01])
plot += plt_mesh

Scalars can be updated interactively using ipywidgets communication:


In [3]:
plt_mesh.attribute = 2*x**2+y**2

It is possible to send time series of an attribute values:


In [4]:
plt_mesh.attribute = {str(t):3*t*x**2+y**2 for t in np.linspace(0,2,20)}