{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### New to Plotly?\n",
"Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/).\n",
"
You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online).\n",
"
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!\n",
"#### Version Check\n",
"Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'2.0.7'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly \n",
"plotly.__version__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 3D Surface Subplots"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/graph_objs/_deprecations.py:477: DeprecationWarning:\n",
"\n",
"plotly.graph_objs.Scene is deprecated.\n",
"Please replace it with one of the following more specific types\n",
" - plotly.graph_objs.Scene\n",
"\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is the format of your plot grid:\n",
"[ (1,1) scene1 ] [ (1,2) scene2 ]\n",
"[ (2,1) scene3 ] [ (2,2) scene4 ]\n",
"\n"
]
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"from plotly import tools\n",
"\n",
"import numpy as np\n",
"\n",
"x = np.linspace(-5, 80, 10)\n",
"y = np.linspace(-5, 60, 10)\n",
"xGrid, yGrid = np.meshgrid(y, x)\n",
"z = xGrid ** 3 + yGrid ** 3\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",
")\n",
"\n",
"fig = tools.make_subplots(rows=2, cols=2,\n",
" specs=[[{'is_3d': True}, {'is_3d': True}],\n",
" [{'is_3d': True}, {'is_3d': True}]])\n",
"\n",
"# adding surfaces to subplots.\n",
"fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='Viridis',\n",
" scene='scene1', showscale=False), 1, 1)\n",
"fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='RdBu',\n",
" scene='scene2', showscale=False), 1, 2)\n",
"fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='YlOrRd',\n",
" scene='scene3', showscale=False), 2, 1)\n",
"fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='YlGnBu',\n",
" scene='scene4', showscale=False), 2, 2)\n",
"\n",
"fig['layout'].update(title='subplots with different colorscales',\n",
" height=800, width=800)\n",
"fig['layout']['scene1'].update(scene)\n",
"fig['layout']['scene2'].update(scene)\n",
"fig['layout']['scene3'].update(scene)\n",
"fig['layout']['scene4'].update(scene)\n",
"\n",
"py.iplot(fig, file_name='multiple_plots')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Reference"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"See https://plotly.com/python/subplots/ for more information regarding subplots!"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning:\n",
"\n",
"The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n",
"\n",
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning:\n",
"\n",
"Did you \"Save\" this notebook before running this command? Remember to save, always save.\n",
"\n"
]
}
],
"source": [
"from IPython.display import display, HTML\n",
"\n",
"display(HTML(''))\n",
"display(HTML(''))\n",
"\n",
"#!pip install git+https://github.com/plotly/publisher.git --upgrade\n",
" \n",
"import publisher\n",
"publisher.publish(\n",
" '3d-subplots.ipynb', 'python/3d-subplots/', 'Python 3D Subplots | plotly',\n",
" '3D Subplots in Plotly',\n",
" title= '3D Subplots in Python | plotly',\n",
" name = '3D Subplots',\n",
" has_thumbnail='true', thumbnail='thumbnail/3d-subplots.jpg', \n",
" language='python', \n",
" display_as='3d_charts', order=0.104,\n",
" ipynb= '~notebook_demo/75')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 1
}