{ "cells": [ { "cell_type": "code", "execution_count": 100, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import json\n", "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "import math\n", "from plotly import tools\n", "import copy\n", "\n", "\n", "#data related to the ring cyclide is loaded\n", "\n", "with open('2381.json') as data_file:\n", " fig = json.load(data_file)\n", "\n", "\n", "data_original = fig['data'][0] #this will be trace0\n", "\n", "data = copy.deepcopy(fig['data'])[0] #trace1" ] }, { "cell_type": "code", "execution_count": 101, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "300\n", "300\n" ] } ], "source": [ "lx = len(data['z'])\n", "ly = len(data['z'][0])\n", "\n", "out = []\n", "\n", "\n", "def dist_origin(x, y, z):\n", "\n", " return math.sqrt((1.0 * x)**2 + (1.0 * y)**2 + (1.0 * z)**2)\n", "\n", "for i in xrange(lx):\n", " temp = []\n", " for j in xrange(ly):\n", " temp.append(\n", " dist_origin(data['x'][i][j], data['y'][i][j], data['z'][i][j]))\n", " out.append(temp)\n", "\n", "print(len(out))\n", "print(len(out[0]))\n", "\n", "data['surfacecolor'] = out #sets surface-color to distance from the origin" ] }, { "cell_type": "code", "execution_count": 102, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[u'name', u'colorscale', 'surfacecolor', u'y', u'x', u'z', u'type']\n", "[u'name', u'colorscale', u'y', u'x', u'z', u'type']\n" ] } ], "source": [ "print(data.keys())\n", "print(data_original.keys())" ] }, { "cell_type": "code", "execution_count": 103, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This is the format of your plot grid:\n", "[ (1,1) scene1 ] [ (1,2) scene2 ]\n", "\n" ] } ], "source": [ "## This section deals with the layout of the plot\n", "\n", "scene = dict(\n", " xaxis=dict(\n", " gridcolor='rgb(255, 255, 255)',\n", " zerolinecolor='rgb(255, 255, 255)',\n", " showbackground=True,\n", " backgroundcolor='rgb(230, 230,230)'\n", " ),\n", " yaxis=dict(\n", " gridcolor='rgb(255, 255, 255)',\n", " zerolinecolor='rgb(255, 255, 255)',\n", " showbackground=True,\n", " backgroundcolor='rgb(230, 230,230)'\n", " ),\n", " zaxis=dict(\n", " gridcolor='rgb(255, 255, 255)',\n", " zerolinecolor='rgb(255, 255, 255)',\n", " showbackground=True,\n", " backgroundcolor='rgb(230, 230,230)'\n", " ),\n", " cameraposition = [[0.2, 0.5, 0.5, 0.2], [0, 0, 0], 3.5]\n", ")\n", "\n", "fig = tools.make_subplots(rows=1, cols=2,\n", " specs=[[{'is_3d': True}, {'is_3d': True}]])\n", "\n", "# adding surfaces to subplots.\n", "data_original['scene'] = 'scene1'\n", "data_original['colorbar'] = dict(x=-0.07)\n", "\n", "data['scene'] = 'scene2'\n", "fig.append_trace(data_original, 1, 1)\n", "fig.append_trace(data, 1, 2)\n", "\n", "\n", "fig['layout'].update(title='Ring Cyclide',\n", " height=800, width=9000)\n", "fig['layout']['scene1'].update(scene)\n", "fig['layout']['scene2'].update(scene)\n", "fig['layout']['annotations'] = [\n", " dict(\n", " x=0.1859205,\n", " y=0.95, #0.9395833,\n", " xref='x',\n", " yref='y',\n", " text='4th Dim Prop. to z',\n", " showarrow=False\n", " ),\n", " dict(\n", " x=0.858,\n", " y=0.95,\n", " xref='x',\n", " yref='y',\n", " text='4th Dim Prop. to Distance from Origin',\n", " showarrow=False\n", " )\n", " \n", " ]\n", "\n", "\n", "plot_url = py.plot(fig, filename='multiple_surface_plots', auto_open=False)" ] }, { "cell_type": "code", "execution_count": 104, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tools.embed('https://plotly.com/~kevintest/333/ring-cyclide/')" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Requirement already up-to-date: publisher in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages\r\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", " warnings.warn('Did you \"Save\" this notebook before running this command? '\n", "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:58: UserWarning: Your URL has more than 2 parts... are you sure?\n", " warnings.warn('Your URL has more than 2 parts... are you sure?')\n" ] } ], "source": [ "from IPython.display import display, HTML\n", "\n", "display(HTML(''))\n", "display(HTML(''))\n", "\n", "! pip install publisher --upgrade\n", "import publisher\n", "publisher.publish(\n", " 'surface-subplots.ipynb', 'python/demo/surface-subplots//', 'Surface Subplot Demo',\n", " 'Surface Subplot Demo',\n", " title = 'Surface Subplot Demo',\n", " thumbnail='', language='python',\n", " layout='user-guide', has_thumbnail='false') " ] }, { "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.9" } }, "nbformat": 4, "nbformat_minor": 0 }