Black Lives Matter. Please consider donating to Black Girls Code today.

Polar chart - fill percent of aea like a pie chart

Hi guys,

Maybe I’m just dumb, but I’ve been trying all night with no luck.

Is it possible to fill an area of a polar chart like a pie chart?

I don’t want the fill to go over zero. It should rotate around 0, like a pie chat would.

I’ve changed the fill attribute to ‘tonext’ and ‘toself’, both produce the same result.

newplot

theta = np.linspace(120, 310, 1000)
r = np.ones(len(theta))

polar_data = [
    go.Scatterpolar(
        r = r,
        theta = theta,
        mode = 'lines',
        fill = 'toself',
        fillcolor = '#0A8883',
        marker = dict(color = '#0A8883'),
        opacity = 0.7
    )
]

polar_layout = go.Layout(
    title='',
    showlegend = False,
    autosize=False,
    width=450,
    height=500,
    margin=go.layout.Margin(
         l=40,
         r=80,
         b=50,
         t=50,
         pad=0),
    polar = dict(radialaxis = dict(tickfont = dict(size = 12)),
                 angularaxis = dict(tickfont = dict(size = 12),
                                    rotation = 90,
                                    direction = "counterclockwise")),
)

fig = go.Figure(data=polar_data, layout=polar_layout)

Ahh ok, I’ve fixed it. The 2:36am magic has helped.

You have to start/finish the arrays with 0. This forces the fill to go to zero at either end.

theta = np.array([0])
theta = np.append(theta, np.linspace(120, 310, 1000))
theta = np.append(theta, 0)
r = np.array([0])
r = np.append(r, np.ones(len(theta)-2))
r = np.append(r, 0)

Hi @anon30707302, glad you got something working!

Just wanted to point out that you could also do this with a single bar in a barpolar trace (https://plot.ly/python/wind-rose-charts/).

import plotly.graph_objs as go

fig = go.Figure()
bp = fig.add_barpolar(r=[1], theta=[315], width=[180])

-Jon

1 Like

Oh perfect, even better! Thanks!