I’ve adapted the following code snipped from this post: graph - Python Plotly Polar Chart Slice Alignment - Stack Overflow
Here is the adaptation:
labels = df.index.tolist()[1:]
ratings = scaled_bidrates
weights = df['sum_cnt'].dropna()
def make_barpolar(ratings, weights, labels=None, colors=None, layout_options = None, **fig_kwargs):
# infer slice angles
angles = [(weight / sum(weights) * 360) for weight in weights]
num_slices = len(ratings)
theta = [0.5 * angle for angle in angles]
for index, angle in enumerate(angles):
for subsequent_index in range(index + 1, len(angles)):
theta[subsequent_index] += angle
print("angles", angles)
print("theta", theta)
width = angles
# optionally infer colors
# if colors is None:
# color_seq = px.colors.sequential.Reds
# color_indices = range(0, len(color_seq), len(color_seq) // num_slices)
# colors = [color_seq[i] for i in color_indices]
if layout_options is None:
layout_options = {}
if labels is None:
labels = ["" for _ in range(num_slices)]
layout_options["showlegend"] = False
# make figure
barpolar_plots = [go.Barpolar(r=[r], theta=[t], width=[w], name=n, **fig_kwargs)
for r, t, w, n in zip(ratings, theta, width, labels)]
fig = go.Figure(barpolar_plots)
# additional layout parameters
fig.update_layout(**layout_options)
return fig
layout_options = {"title": "FPP Chart",
"title_font_size": 24,
"title_x": 0.5,
"legend_x": 0.85,
"legend_y": 0.5,
"polar_radialaxis_ticks": "",
"polar_radialaxis_showticklabels": False,
"polar_radialaxis_range": [0, max(ratings)],
"polar_angularaxis_ticks": "",
"polar_angularaxis_showticklabels": False}
fig = make_barpolar(ratings, weights, labels, layout_options=layout_options, opacity = 0.3)
fig.update_traces(marker={
"colorscale": px.colors.sequential.Reds,
"showscale": True,
"color": df['winrate'].dropna(),
"line_color": None,
"line_width": 1,
"cmin": df['winrate'].min(),
"cmax": df['winrate'].max(),
}, selector=dict(type='barpolar'))
fig.show()
print(fig.data)
And the result is not what I intended.
I’ve tried printing fig.data
to see there is an issue with the data but the values are there.
What am I missing?