{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Vector field animation\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import k3d\n", "import numpy as np\n", "import time \n", "\n", "plot = k3d.plot()\n", "\n", "Nx,Ny = 10,10\n", "\n", "x = np.linspace(-1,1,Nx)\n", "y = np.linspace(-2,2,Ny)\n", "\n", "x,y = np.meshgrid(x,y)\n", "z = np.zeros_like(x)\n", "\n", "origins = np.vstack([x.flatten(),y.flatten(),z.flatten()]).T\n", "vectors = 0.5*(np.vstack([np.zeros_like(x.flatten()),np.zeros_like(x.flatten()),np.ones_like(x.flatten())] )).T\n", "phi0 = np.linspace(0,2*np.pi,vectors.shape[0])\n", "labels = [str(i) for i in range(vectors.shape[0])]\n", "vector_plot = k3d.vectors(origins.astype(np.float32), vectors.astype(np.float32))\n", "\n", "plot += vector_plot\n", "plot.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.camera_auto_fit = False\n", "plot.grid_auto_fit = False\n", "\n", "for phi in np.linspace(0,2*np.pi,55):\n", " r = 0.1 \n", " v = vector_plot.vectors.copy()\n", " v[:,0] += r*np.cos(phi+phi0)\n", " v[:,1] += r*np.sin(phi+phi0)\n", " vector_plot.vectors = v\n", " time.sleep(0.05) # have to wait for real data update" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" }, "widgets": { "state": { "e8e906fba93843f3af98e01c81918353": { "views": [ { "cell_index": 2 } ] } }, "version": "1.2.0" } }, "nbformat": 4, "nbformat_minor": 1 }