#!/usr/bin/env python # coding: utf-8 # In[ ]: import k3d import numpy as np N = 100 theta = np.linspace(0, 2.0 * np.pi, N) phi = np.linspace(0, 2.0 * np.pi, N) theta, phi = np.meshgrid(theta, phi) c, a = 2, 1 x = (c + a * np.cos(theta)) * np.cos(phi) y = (c + a * np.cos(theta)) * np.sin(phi) z = a * np.sin(theta) vertices = np.dstack([x, y, z]).astype(np.float32) indices = (np.stack([ np.arange(N*N) + 0, np.arange(N*N) + N, np.arange(N*N) + N + 1, np.arange(N*N) + 0, np.arange(N*N) + N + 1, np.arange(N*N) + 1 ]).T % (N * N)).astype(np.uint32) plot = k3d.plot() plot += k3d.points(vertices, point_size=0.05, shader='3d', color=0) mesh = k3d.mesh(vertices, indices, flat_shading=False, attribute=phi, color_map=k3d.matplotlib_color_maps.twilight) plot += mesh plot.display() # In[ ]: mesh.attribute = [] plot.colorbar_object_id = -1 mesh.colors = np.random.randint(0, 0xFFFFFF, N * N).astype(np.uint32) # In[ ]: # In[ ]: