{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Dynamically change surface plot data\n", "\n", "Note that in this case each time the dataset is transferred.\n", "(opposite to marching cubes plot)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from k3d import K3D\n", "import numpy as np\n", "from ipywidgets import interact, interactive, fixed\n", "import ipywidgets as widgets\n", "import time\n", "plot = K3D()\n", "#plot.display()\n", "\n", "plot += K3D.vectors(\n", " (0,0,0,0,0,0,0,0,0), \n", " (1,0,0,0,1,0,0,0,1), \n", " colors=(0xff0000, 0xff0000, 0x0000ff, 0x0000ff, 0x00ff00, 0x00ff00), \n", " labels=('Axis x', 'Axis y', 'Axis z')\n", ")\n", "\n", "Nx = 264\n", "Ny = 264\n", "xmin,xmax = -3,3\n", "ymin,ymax = 0,3\n", "x = np.linspace(xmin,xmax,Nx)\n", "y = np.linspace(ymin,ymax,Ny)\n", "x,y = np.meshgrid(x,y,indexing='ij')\n", "surface = K3D.surface(np.sin(x**2+y**2),xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,\\\n", " color=np.random.randint(0, 0xFFFFFF, 1)[0])\n", "\n", "plot += surface\n", "plot.camera_auto_fit = False" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "surface.heights = (np.sin(x**2)+np.cos(y**3))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "surface.color=0xff0000" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "@interact(phi=widgets.FloatSlider(value=0.,min=0,max=2*np.pi,step=0.1))\n", "def g(phi):\n", " f = np.sin(x**2+y**2-phi)\n", " surface.heights = f" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "plot.display()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%time data = (np.sin(x**2)+np.cos(y**3))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%time surface.heights = data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }