{
"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": [
"#### Legacy Plot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"These polar charts are legacy and will likely be deprecated in [Plotly 2.0](https://github.com/plotly/plotly.js/issues/420). Please see the new `scatterpolar` and `scatterpolargl` [trace types](https://plotly.com/python/polar-chart/) for latest and greatest in Plotly polar coordinates."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Basic Polar Chart"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"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",
"import pandas as pd\n",
"\n",
"df = pd.read_csv('polar_dataset.csv')\n",
"\n",
"trace1 = go.Scatter(\n",
" r=df['x1'],\n",
" t=df['y'],\n",
" mode='lines',\n",
" name='go.Figure8',\n",
" marker=dict(\n",
" color='none',\n",
" line=dict(\n",
" color='peru'\n",
" )\n",
" )\n",
")\n",
"trace2 = go.Scatter(\n",
" r=df['x2'],\n",
" t=df['y'],\n",
" mode='lines',\n",
" name='Cardioid',\n",
" marker=dict(\n",
" color='none',\n",
" line=dict(\n",
" color='darkviolet'\n",
" )\n",
" )\n",
")\n",
"trace3 = go.Scatter(\n",
" r=df['x3'],\n",
" t=df['y'],\n",
" mode='lines',\n",
" name='Hypercardioid',\n",
" marker=dict(\n",
" color='none',\n",
" line=dict(\n",
" color='deepskyblue'\n",
" )\n",
" )\n",
")\n",
"trace4 = go.Scatter(\n",
" r=df['x4'],\n",
" t=df['y'],\n",
" mode='lines',\n",
" name='Subcardioid',\n",
" marker=dict(\n",
" color='none',\n",
" line=dict(\n",
" color='orangered'\n",
" )\n",
" )\n",
")\n",
"trace5 = go.Scatter(\n",
" r=df['x5'],\n",
" t=df['y'],\n",
" mode='lines',\n",
" name='Supercardioid',\n",
" marker=dict(\n",
" color='none',\n",
" line=dict(\n",
" color='green'\n",
" )\n",
" )\n",
")\n",
"data = [trace1, trace2, trace3, trace4, trace5]\n",
"layout = go.Layout(\n",
" title='Mic Patterns',\n",
" font=dict(\n",
" family='Arial, sans-serif;',\n",
" size=12,\n",
" color='#000'\n",
" ),\n",
" orientation=-90\n",
")\n",
"fig = go.Figure(data=data, layout=layout)\n",
"py.iplot(fig, filename='polar-line')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Polar Scatter Chart"
]
},
{
"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",
"import numpy as np\n",
"\n",
"trace1 = go.Scatter(\n",
" r = np.random.uniform(1,6,size=62),\n",
" t = np.random.uniform(30,5,size=62),\n",
" mode='markers',\n",
" name='Trial 1',\n",
" marker=dict(\n",
" color='rgb(27,158,119)',\n",
" size=110,\n",
" line=dict(\n",
" color='white'\n",
" ),\n",
" opacity=0.7\n",
" )\n",
")\n",
"trace2 = go.Scatter(\n",
" r=np.random.uniform(3,8,size=62),\n",
" t=np.random.uniform(-14,-76,size=62),\n",
" mode='markers',\n",
" name='Trial 2',\n",
" marker=dict(\n",
" color='rgb(217,95,2)',\n",
" size=110,\n",
" line=dict(\n",
" color='white'\n",
" ),\n",
" opacity=0.7\n",
" )\n",
")\n",
"trace3 = go.Scatter(\n",
" r=np.random.uniform(1,7,size=62),\n",
" t=np.random.uniform(131,111,size=62),\n",
" mode='markers',\n",
" name='Trial 3',\n",
" marker=dict(\n",
" color='rgb(117,112,179)',\n",
" size=110,\n",
" line=dict(\n",
" color='white'\n",
" ),\n",
" opacity=0.7\n",
" )\n",
")\n",
"trace4 = go.Scatter(\n",
" r=np.random.uniform(1,9,size=62),\n",
" t=np.random.uniform(-140,-177,size=62),\n",
" mode='markers',\n",
" name='Trial 4',\n",
" marker=dict(\n",
" color='rgb(231,41,138)',\n",
" size=110,\n",
" line=dict(\n",
" color='white'\n",
" ),\n",
" opacity=0.7\n",
" )\n",
")\n",
"trace5 = go.Scatter(\n",
" r=np.random.uniform(1,3,size=62),\n",
" t=np.random.uniform(-100,-163,size=62),\n",
" mode='markers',\n",
" name='Trial 5',\n",
" marker=dict(\n",
" color='rgb(102,166,30)',\n",
" size=110,\n",
" line=dict(\n",
" color='white'\n",
" ),\n",
" opacity=0.7\n",
" )\n",
")\n",
"trace6 = go.Scatter(\n",
" r=np.random.uniform(0,5,size=62),\n",
" t=np.random.uniform(66,47,size=62),\n",
" mode='markers',\n",
" name='Trial 6',\n",
" marker=dict(\n",
" color='rgb(230,171,2)',\n",
" size=110,\n",
" line=dict(\n",
" color='white'\n",
" ),\n",
" opacity=0.7\n",
" )\n",
")\n",
"data = [trace1, trace2, trace3, trace4, trace5, trace6]\n",
"layout = go.Layout(\n",
" title='Hobbs-Pearson Trials',\n",
" font=dict(\n",
" size=15\n",
" ),\n",
" plot_bgcolor='rgb(223, 223, 223)',\n",
" angularaxis=dict(\n",
" tickcolor='rgb(253,253,253)'\n",
" )\n",
")\n",
"fig = go.Figure(data=data, layout=layout)\n",
"py.iplot(fig)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Wind Rose Chart"
]
},
{
"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",
"trace1 = go.Area(\n",
" r=[77.5, 72.5, 70.0, 45.0, 22.5, 42.5, 40.0, 62.5],\n",
" t=['North', 'N-E', 'East', 'S-E', 'South', 'S-W', 'West', 'N-W'],\n",
" name='11-14 m/s',\n",
" marker=dict(\n",
" color='rgb(106,81,163)'\n",
" )\n",
")\n",
"trace2 = go.Area(\n",
" r=[57.49999999999999, 50.0, 45.0, 35.0, 20.0, 22.5, 37.5, 55.00000000000001],\n",
" t=['North', 'N-E', 'East', 'S-E', 'South', 'S-W', 'West', 'N-W'],\n",
" name='8-11 m/s',\n",
" marker=dict(\n",
" color='rgb(158,154,200)'\n",
" )\n",
")\n",
"trace3 = go.Area(\n",
" r=[40.0, 30.0, 30.0, 35.0, 7.5, 7.5, 32.5, 40.0],\n",
" t=['North', 'N-E', 'East', 'S-E', 'South', 'S-W', 'West', 'N-W'],\n",
" name='5-8 m/s',\n",
" marker=dict(\n",
" color='rgb(203,201,226)'\n",
" )\n",
")\n",
"trace4 = go.Area(\n",
" r=[20.0, 7.5, 15.0, 22.5, 2.5, 2.5, 12.5, 22.5],\n",
" t=['North', 'N-E', 'East', 'S-E', 'South', 'S-W', 'West', 'N-W'],\n",
" name='< 5 m/s',\n",
" marker=dict(\n",
" color='rgb(242,240,247)'\n",
" )\n",
")\n",
"data = [trace1, trace2, trace3, trace4]\n",
"layout = go.Layout(\n",
" title='Wind Speed Distribution in Laurel, NE',\n",
" font=dict(\n",
" size=16\n",
" ),\n",
" legend=dict(\n",
" font=dict(\n",
" size=16\n",
" )\n",
" ),\n",
" radialaxis=dict(\n",
" ticksuffix='%'\n",
" ),\n",
" orientation=270\n",
")\n",
"fig = go.Figure(data=data, layout=layout)\n",
"py.iplot(fig, filename='polar-area-chart')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Reference\n",
"\n",
"See https://plotly.com/python/reference/#area for more information and chart attribute options!"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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\\branden\\appdata\\local\\temp\\pip-ejnl58xs-build\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:\\Users\\Branden\\Anaconda3\\envs\\ipykernel_py2\\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:\\Users\\Branden\\Anaconda3\\envs\\ipykernel_py2\\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",
" 'polar.ipynb', 'python/legacy-polar-chart/', 'Polar Charts [Legacy]',\n",
" 'Legacy polar charts in python.',\n",
" title = 'Python Polar Charts | plotly',\n",
" has_thumbnail='true', thumbnail='thumbnail/polar-scatter.jpg', \n",
" language='python', \n",
" display_as='legacy_charts', order=1,\n",
" ipynb= '~notebook_demo/37') "
]
},
{
"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
}