Final tests
import k3d
k3d.version
from k3d import K3D
import numpy as np
plot = K3D()
plot.display()
plot += K3D.vectors(
(0,0,0,0,0,0,0,0,0),
(1,0,0,0,1,0,0,0,1),
colors=(0xff0000, 0xff0000, 0x0000ff, 0x0000ff, 0x00ff00, 0x00ff00),
labels=('Axis x', 'Axis y', 'Axis z')
)
Nx = 260
Ny = 260
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')
plot += K3D.surface(np.sin(x**2+y**2),xmin=xmin,xmax=xmax,ymin=ymin,\
ymax=ymax, color=np.random.randint(0, 0xFFFFFF, 1)[0])
plot.camera_auto_fit = False
%%time
for i in range(4):
Nx,Ny = np.random.randint(80,100,size=2)
dx,dy = 2*np.random.random(2)
x0,y0 = 1*np.random.random(2)
xmin,xmax = x0-dx, x0+dx
ymin,ymax = y0-dy, y0+dy
x = np.linspace(xmin,xmax,Nx)
y = np.linspace(ymin,ymax,Ny)
x,y = np.meshgrid(x,y,indexing='ij')
plot += K3D.surface(np.sin(x**2+y**2),\
xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, color=np.random.randint(0, 0xFFFFFF, 1)[0])
CPU times: user 18.9 ms, sys: 1.82 ms, total: 20.7 ms Wall time: 19.3 ms
plot += K3D.text("O", position=(0, 0, 0) )
plot += K3D.text("X max", position=(3, 0, 0) )
plot += K3D.text("X min", position=(-3, 0, 0) )
plot += K3D.text("Z min", position=(0, 0, -1) )
plot += K3D.text("Z max", position=(0, 0, 1) )
plot += K3D.text("Y min", position=(0, -3, 0) )
plot += K3D.text("Y max", position=(0, 3, 0) )
x = x.flatten()
y = y.flatten()
z = np.sin(x**2+y**2)
points = np.vstack([x,y,z]).T
plot += K3D.points(points,colors=np.ones_like(x)*0xFF0F00 ,point_size=4)
x = np.linspace(xmin,xmax,Nx)
y = np.linspace(ymin,ymax,Ny)
x, y = np.meshgrid(x,y,indexing='ij')
for i in range(0,Ny-1,5):
x_ = x[:,i]
y_ = y[:,i]
z = np.sin(x_**2+y_**2)
points = np.vstack([x_,y_,z]).T
plot += K3D.line(points,color=0x00FF00 ,width=5)
x = np.linspace(xmin,xmax,Nx)
y = np.linspace(ymin,ymax,Ny)
dx, dy = x[1]-x[0],y[1]-y[0]
x,y = np.meshgrid(x,y,indexing='ij')
z = np.sin(x**2+y**2)
dx,dy
dFx,dFy = np.gradient(z)
origins = np.vstack([x.flatten(),y.flatten(),z.flatten()]).T
vectors = 0.01*(np.vstack([dFx.flatten()/dx,dFy.flatten()/dy,-np.ones(Nx*Ny)] )).T
vector_plot = K3D.vectors(origins,vectors)
plot += vector_plot
def normalized(a, axis=-1, order=2):
l2 = np.atleast_1d(np.linalg.norm(a, order, axis))
l2[l2==0] = 1
return a / np.expand_dims(l2, axis)
plot -= vector_plot
vector_plot = K3D.vectors(origins[::8],-0.4*normalized(vectors[::8]),color=0x00ff00, line_width=2)
plot += vector_plot
Nz = Nx
zmin,zmax = -1,1
ymin,ymax = -1,3
x = np.linspace(xmin,xmax,Nx)
y = np.linspace(ymin,ymax,Ny)
z = np.linspace(zmin,zmax,Nz)
x,y,z = np.meshgrid(x,y,z,indexing='ij')
plot += K3D.marching_cubes(np.sin(x**2+y**2)-z,\
xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, \
zmin=zmin, zmax=zmax, level=0.0,color=0xff0000)