#!/usr/bin/env python # coding: utf-8 # ## Vector field animation # # # # In[ ]: import k3d import numpy as np import time plot = k3d.plot() Nx,Ny = 10,10 x = np.linspace(-1,1,Nx) y = np.linspace(-2,2,Ny) x,y = np.meshgrid(x,y) z = np.zeros_like(x) origins = np.vstack([x.flatten(),y.flatten(),z.flatten()]).T vectors = 0.5*(np.vstack([np.zeros_like(x.flatten()),np.zeros_like(x.flatten()),np.ones_like(x.flatten())] )).T phi0 = np.linspace(0,2*np.pi,vectors.shape[0]) labels = [str(i) for i in range(vectors.shape[0])] vector_plot = k3d.vectors(origins.astype(np.float32), vectors.astype(np.float32)) plot += vector_plot plot.display() # In[ ]: plot.camera_auto_fit = False plot.grid_auto_fit = False for phi in np.linspace(0,2*np.pi,55): r = 0.1 v = vector_plot.vectors.copy() v[:,0] += r*np.cos(phi+phi0) v[:,1] += r*np.sin(phi+phi0) vector_plot.vectors = v time.sleep(0.05) # have to wait for real data update # In[ ]: