{ "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": {}, "outputs": [], "source": [ "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.plot()\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=int(np.random.randint(0, 0xFFFFFF, 1)[0]))\n", "\n", "plot += surface\n", "plot.camera_auto_fit = False\n", "plot.grid_auto_fit = False" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "surface.heights = (np.sin(x**2)+np.cos(y**3))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "surface.color=0xff0000" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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": {}, "outputs": [], "source": [ "plot.display()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%time data = (np.sin(x**2)+np.cos(y**3))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%time surface.heights = data+2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "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.0" } }, "nbformat": 4, "nbformat_minor": 1 }