{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from IPython.core.display import display, HTML\n", "import json\n", "import numpy as np\n", "\n", "def plot3D(X, Y, Z, height=600, xlabel = \"X\", ylabel = \"Y\", zlabel = \"Z\", initialCamera = None):\n", "\n", " options = {\n", " \"width\": \"100%\",\n", " \"style\": \"surface\",\n", " \"showPerspective\": True,\n", " \"showGrid\": True,\n", " \"showShadow\": False,\n", " \"keepAspectRatio\": True,\n", " \"height\": str(height) + \"px\"\n", " }\n", "\n", " if initialCamera:\n", " options[\"cameraPosition\"] = initialCamera\n", " \n", " data = [ {\"x\": X[y,x], \"y\": Y[y,x], \"z\": Z[y,x]} for y in range(X.shape[0]) for x in range(X.shape[1]) ]\n", " visCode = r\"\"\"\n", " \n", " \n", "
\n", "
\n", " \n", " \"\"\"\n", " htmlCode = \"\"\n", " display(HTML(htmlCode))" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "X, Y = np.meshgrid(np.linspace(-3,3,50),np.linspace(-3,3,50))\n", "Z = np.sin(X**2 + Y**2)**2/(X**2+Y**2)\n", "plot3D(X, Y, Z)" ] }, { "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.1" } }, "nbformat": 4, "nbformat_minor": 2 }