Show Sidebar Hide Sidebar

Polar Charts in Pandas

How to graph polar charts in pandas.

# Learn about API authentication here: https://plot.ly/pandas/getting-started
# Find your api_key here: https://plot.ly/settings/api

import plotly.plotly as py
import plotly.graph_objs as go

import pandas as pd
import numpy as np

N = 100.0
r = dict( r = [ np.random.poisson(N)*(np.cos((i/4)*np.pi/180)) for i in range(360) ] )
df = pd.DataFrame(r)
df_ma = pd.ewma(df,4.0)
df_ma.head()

data = []
data.append(
    go.Scatterpolar(
        theta=df.index,
        r=df['r'],
        name = 'Scatter',
        mode='markers',
        marker=dict(
            color='rgb(255,78,252)',
            size=8 )
    ) )
data.append(
    go.Scatterpolar(
        theta=df_ma.index,
        r=df_ma['r'],
        name = 'Moving average',
        mode='lines',
        line=dict(color='rgb(69,124,235)'),
        marker=dict(
            color='rgb(69,124,235)',
            line= dict(width=2,
            color='rgb(69,124,235)') ),
    ) )
layout = go.Layout(
    angularaxis=dict(
        tickcolor='#CCC',
        showline=False,
    )
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='pandas-polar-chart')
How to make polar charts in Pandas on the polar coordinate system.
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.