{
"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!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 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.7.0'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly\n",
"plotly.__version__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Basic 3D Cone"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"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",
"data = [{\n",
" 'type': 'cone',\n",
" 'x': [1], 'y': [1], 'z': [1],\n",
" 'u': [1], 'v': [1], 'w': [0]\n",
"}]\n",
"\n",
"layout = {\n",
" 'scene': {\n",
" 'camera': {\n",
" 'eye': {'x': -0.76, 'y': 1.8, 'z': 0.92}\n",
" }\n",
" }\n",
"}\n",
"\n",
"fig = {\"data\": data, \"layout\": layout}\n",
"py.iplot(fig, filename='cone-basic', validate=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Multiple 3D Cones"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"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",
"data = [{\n",
" \"type\": \"cone\",\n",
" \"x\": [1, 2, 3],\n",
" \"y\": [1, 2, 3],\n",
" \"z\": [1, 2, 3],\n",
" \"u\": [1, 0, 0],\n",
" \"v\": [0, 3, 0],\n",
" \"w\": [0, 0, 2],\n",
" \"sizemode\": \"absolute\",\n",
" \"sizeref\": 2,\n",
" \"anchor\": \"tip\",\n",
" \"colorbar\": {\n",
" \"x\": 0,\n",
" \"xanchor\": \"right\",\n",
" \"side\": \"left\"\n",
" }\n",
"}]\n",
"\n",
"layout = {\n",
" \"scene\": {\n",
" \"domain\": {\"x\": [0, 1]},\n",
" \"camera\": {\n",
" \"eye\": {\"x\": -1.57, \"y\": 1.36, \"z\": 0.58}\n",
" }\n",
" }\n",
"}\n",
"\n",
"fig = {\"data\": data, \"layout\": layout}\n",
"py.iplot(fig, filename=\"cone-mulitple\", validate=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3D Cone Lighting"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"data = [{\n",
" \"type\": \"cone\",\n",
" \"name\": \"base\",\n",
" \"x\": [1, 1, 1],\n",
" \"y\": [1, 2, 3],\n",
" \"z\": [1, 1, 1],\n",
" \"u\": [1, 2, 3],\n",
" \"v\": [1, 1, 2],\n",
" \"w\": [4, 4, 1],\n",
" \"hoverinfo\": \"u+v+w+name\",\n",
" \"showscale\": False\n",
" },{\n",
" \"type\": \"cone\",\n",
" \"name\": \"opacity:0.3\",\n",
" \"x\": [2, 2, 2],\n",
" \"y\": [1, 2, 3],\n",
" \"z\": [1, 1, 1],\n",
" \"u\": [1, 2, 3],\n",
" \"v\": [1, 1, 2],\n",
" \"w\": [4, 4, 1],\n",
" \"hoverinfo\": \"u+v+w+name\",\n",
" \"showscale\": False,\n",
" \"opacity\": 0.3\n",
" },{\n",
" \"type\": \"cone\",\n",
" \"name\": \"lighting.ambient:0.3\",\n",
" \"x\": [3, 3, 3],\n",
" \"y\": [1, 2, 3],\n",
" \"z\": [1, 1, 1],\n",
" \"u\": [1, 2, 3],\n",
" \"v\": [1, 1, 2],\n",
" \"w\": [4, 4, 1],\n",
" \"hoverinfo\": \"u+v+w+name\",\n",
" \"showscale\": False,\n",
" \"lighting\": {\"ambient\": 0.3}\n",
" },{\n",
" \"type\": \"cone\",\n",
" \"name\": \"lighting.diffuse:0.3\",\n",
" \"x\": [4, 4, 4],\n",
" \"y\": [1, 2, 3],\n",
" \"z\": [1, 1, 1],\n",
" \"u\": [1, 2, 3],\n",
" \"v\": [1, 1, 2],\n",
" \"w\": [4, 4, 1],\n",
" \"hoverinfo\": \"u+v+w+name\",\n",
" \"showscale\": False,\n",
" \"lighting\": {\"diffuse\": 0.3}\n",
" },{\n",
" \"type\": \"cone\",\n",
" \"name\": \"lighting.specular:2\",\n",
" \"x\": [5, 5, 5],\n",
" \"y\": [1, 2, 3],\n",
" \"z\": [1, 1, 1],\n",
" \"u\": [1, 2, 3],\n",
" \"v\": [1, 1, 2],\n",
" \"w\": [4, 4, 1],\n",
" \"hoverinfo\": \"u+v+w+name\",\n",
" \"showscale\": False,\n",
" \"lighting\": {\"specular\": 2}\n",
" },{\n",
" \"type\": \"cone\",\n",
" \"name\": \"lighting.roughness:1\",\n",
" \"x\": [6, 6, 6],\n",
" \"y\": [1, 2, 3],\n",
" \"z\": [1, 1, 1],\n",
" \"u\": [1, 2, 3],\n",
" \"v\": [1, 1, 2],\n",
" \"w\": [4, 4, 1],\n",
" \"hoverinfo\": \"u+v+w+name\",\n",
" \"showscale\": False,\n",
" \"lighting\": {\"roughness\": 1}\n",
" },{\n",
" \"type\": \"cone\",\n",
" \"name\": \"lighting.fresnel:2\",\n",
" \"x\": [7, 7, 7],\n",
" \"y\": [1, 2, 3],\n",
" \"z\": [1, 1, 1],\n",
" \"u\": [1, 2, 3],\n",
" \"v\": [1, 1, 2],\n",
" \"w\": [4, 4, 1],\n",
" \"hoverinfo\": \"u+v+w+name\",\n",
" \"showscale\": False,\n",
" \"lighting\": {\"fresnel\": 2}\n",
" },{\n",
" \"type\": \"cone\",\n",
" \"name\": \"lighting.position x:0,y:0,z:1e5\",\n",
" \"x\": [8, 8, 8],\n",
" \"y\": [1, 2, 3],\n",
" \"z\": [1, 1, 1],\n",
" \"u\": [1, 2, 3],\n",
" \"v\": [1, 1, 2],\n",
" \"w\": [4, 4, 1],\n",
" \"hoverinfo\": \"u+v+w+name\",\n",
" \"showscale\": False,\n",
" \"lightposition\": {\"x\": 0, \"y\": 0, \"z\": 1e5}\n",
" }\n",
"]\n",
"\n",
"layout = {\n",
" \"scene\": {\n",
" \"aspectmode\": \"data\",\n",
" \"camera\": {\n",
" \"eye\": {\"x\": 0.05, \"y\": -2.6, \"z\": 2}\n",
" }\n",
" },\n",
" \"margin\": {\"t\": 0, \"b\": 0, \"l\": 0, \"r\": 0}\n",
"}\n",
"\n",
"fig = {\"data\": data, \"layout\": layout}\n",
"py.iplot(fig, filename=\"cone-lighting\", validate=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3D Cone Vortex"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"import pandas as pd\n",
"\n",
"df = pd.read_csv(\"https://raw.githubusercontent.com/plotly/datasets/master/vortex.csv\")\n",
"\n",
"data = [{\n",
" \"type\": \"cone\",\n",
" \"x\": df['x'],\n",
" \"y\": df['y'],\n",
" \"z\": df['z'],\n",
" \"u\": df['u'],\n",
" \"v\": df['v'],\n",
" \"w\": df['w'],\n",
" \"colorscale\": 'Blues',\n",
" \"sizemode\": \"absolute\",\n",
" \"sizeref\": 40\n",
"}]\n",
"\n",
"layout = {\n",
" \"scene\": {\n",
" \"aspectratio\": {\"x\": 1, \"y\": 1, \"z\": 0.8},\n",
" \"camera\": {\n",
" \"eye\": {\"x\": 1.2, \"y\": 1.2, \"z\": 0.6}\n",
" }\n",
" }\n",
"}\n",
"\n",
"fig = {\"data\": data, \"layout\": layout}\n",
"py.iplot(fig, filename=\"cone-vortex\", validate=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Reference\n",
"See https://plotly.com/python/reference/ for more information and chart attribute options!"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"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 c:\\users\\brand\\appdata\\local\\temp\\pip-req-build-bgjw3jia\n",
"Installing collected packages: publisher\n",
" Found existing installation: publisher 0.11\n",
" Uninstalling publisher-0.11:\n",
" Successfully uninstalled publisher-0.11\n",
" Running setup.py install for publisher: started\n",
" Running setup.py install for publisher: finished with status 'done'\n",
"Successfully installed publisher-0.11\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Python27\\lib\\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",
"C:\\Python27\\lib\\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",
"import publisher\n",
"publisher.publish(\n",
" 'cones.ipynb', 'python/cone-plot/', '3D Cone Plots',\n",
" 'How to make 3D Cone plots in Python with Plotly.',\n",
" title = '3D Cone Plots | Plotly',\n",
" has_thumbnail='true', thumbnail='thumbnail/3dcone.png',\n",
" language='python',\n",
" # page_type='example_index', // note this is only if you want the tutorial to appear on the main page: plot.ly/python\n",
" display_as='3d_charts', order=20, ipynb='~notebook_demo/206',\n",
" redirect_from='python/3d-cone/',\n",
" uses_plotly_offline=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"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.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}