{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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!"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"#### Basic Parametric Plot"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"import numpy as np\n",
"\n",
"s = np.linspace(0, 2 * np.pi, 240)\n",
"t = np.linspace(0, np.pi, 240)\n",
"tGrid, sGrid = np.meshgrid(s, t)\n",
"\n",
"r = 2 + np.sin(7 * sGrid + 5 * tGrid) # r = 2 + sin(7s+5t)\n",
"x = r * np.cos(sGrid) * np.sin(tGrid) # x = r*cos(s)*sin(t)\n",
"y = r * np.sin(sGrid) * np.sin(tGrid) # y = r*sin(s)*sin(t)\n",
"z = r * np.cos(tGrid) # z = r*cos(t)\n",
"\n",
"surface = go.Surface(x=x, y=y, z=z)\n",
"data = [surface]\n",
"\n",
"layout = go.Layout(\n",
" title='Parametric Plot',\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",
"\n",
"fig = go.Figure(data=data, layout=layout)\n",
"py.iplot(fig, filename='Parametric_plot')"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"#### Parameteric Plot with Colorscale"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"import numpy as np\n",
"\n",
"dphi, dtheta = np.pi / 250.0, np.pi / 250.0\n",
"[phi, theta] = np.mgrid[0:np.pi + dphi * 1.5:dphi, 0:2 * np.pi +\n",
" dtheta * 1.5:dtheta]\n",
"m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;\n",
"\n",
"# Applying the parametric equation..\n",
"r = (np.sin(m0 * phi) ** m1 + np.cos(m2 * phi) ** m3 +\n",
" np.sin(m4 * theta) ** m5 + np.cos(m6 * theta) ** m7)\n",
"x = r * np.sin(phi) * np.cos(theta)\n",
"y = r * np.cos(phi)\n",
"z = r * np.sin(phi) * np.sin(theta)\n",
"\n",
"\n",
"surface = go.Surface(x=x, y=y, z=z, colorscale='Viridis')\n",
"data = [surface]\n",
"layout = go.Layout(\n",
" title='Another Parametric Plot',\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 = go.Figure(data=data, layout=layout)\n",
"py.iplot(fig, filename='parametric-plot-viridis')"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"#### Reference"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"See https://plotly.com/python/reference/#surface for more information!"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"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": [
"Collecting git+https://github.com/plotly/publisher.git\n",
" Cloning https://github.com/plotly/publisher.git to /var/folders/ld/6cl3s_l50wd40tdjq2b03jxh0000gp/T/pip-fgJlrn-build\n",
"Installing collected packages: publisher\n",
" Found existing installation: publisher 0.10\n",
" Uninstalling publisher-0.10:\n",
" Successfully uninstalled publisher-0.10\n",
" Running setup.py install for publisher ... \u001b[?25l-\b \b\\\b \bdone\n",
"\u001b[?25hSuccessfully installed publisher-0.10\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/brandendunbar/Desktop/test/venv/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead.\n",
" \"You should import from nbconvert instead.\", ShimWarning)\n",
"/Users/brandendunbar/Desktop/test/venv/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"
]
}
],
"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-parametric.ipynb', 'python/3d-parametric-plots/', '3D Parametric Plots | plotly',\n",
" 'How to 3D Parameteric Plots in Python',\n",
" title= '3D Parametric Plots in Python | plotly',\n",
" name = 'Parametric Plots',\n",
" has_thumbnail='true', thumbnail='thumbnail/parametric.jpg', \n",
" language='python',\n",
" display_as='3d_charts', order=9,\n",
" ipynb= '~notebook_demo/69')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": 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.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}