help(go.layout.Polar.barmode)
Determines how bars at the same location coordinate are
displayed on the graph. With "stack", the bars are stacked on
top of one another With "overlay", the bars are plotted over
one another, you might need to reduce "opacity" to see multiple
bars.
The 'barmode' property is an enumeration that may be specified as:
- One of the following enumeration values:
['stack', 'overlay']
we are noticing that it doesn’t display barmode="group", similar to cartesian case.
But I deduced an algorithm to plot grouped polar bars, according to the number of categories/groups and the bar numbers in each group:
import plotly.graph_objects as go
categories=10
nbar_group=5 #number of bars in a group
step = 360/categories
small_step=step/(nbar_group+1)
theta = [0.5*(2*k-1)*step+small_step*(j+1) for k in range(categories) for j in range(nbar_group)]
r = [12, 10, 7, 5, 2]*categories
tickvals=[k*step for k in range(categories)]
ticktext=["C", "B", "A", "J", "I", "H", "G", "F", "E", "D"]
fig=go.Figure(go.Barpolar(r=r, theta=theta, marker_color=r, marker_colorscale="Blues",
marker_colorbar_thickness=23))
fig.update_layout(width=500, polar=dict(angularaxis=dict(tickvals=tickvals, ticktext=ticktext)))
It really helped! and i’m very close to the final touch, thanks goes to you.
The only issue left, is that it doesn’t recognize the groups, only recognizing one.
Here’s my code below, it’s similar to yours.
categories=10
values=df_timimg_merged['value']
nbar_group=3 #number of bars in a group
step = 360/categories#36
small_step=step/(nbar_group+1)#9
theta = [0.5*(2*k-1)*step+small_step*(j+1) for k in range(categories) for j in range(nbar_group)]
r = values
tickvals=[k*step for k in range(categories)]
ticktext=[5,4,3,2,1,12,11,10,9,8]
fig=go.Figure(go.Barpolar(r=r, theta=theta, marker_color=r, marker_colorscale="Blues",
marker_colorbar_thickness=23))
fig.update_layout(width=500, polar=dict(angularaxis=dict(tickvals=tickvals, ticktext=ticktext)))
And here’s a snapshot of my data:
For each hour, i have 3 groups (3 bars) each group supposed to be with diff color.
Could you post the list of values? The len(r) must be equal to len(theta).
r = [val1, val2, val3, v1, v2, v3, u1, u2, u3, … x1, x2, x3]
i.e. for each group you must give the three values consecutively.
@JayR7
The go.Barpolar works well, when data have r of the same order of magnitude. But in your case min(r)=0, and max(r)=30. Look at the first graph you posted here, and notice how small are the red bars compared to the light blue ones. When we draw them in the group version, only the ones that are blue in your figure are shown, but not those red.
I think that here the bars of small r and theta are lost because they are not overlapped as in your original plot, but each one is assigned a theta value. Most likely the algorithm implemented in plotly.js neglects the bars of small r and/theta.
LE: With matplotlib:
import numpy as np
import matplotlib.pyplot as plt
ax = plt.subplot(projection='polar')
ax.bar(theta, r, width=np.pi/20, bottom=0.0)
plt.show()
it looks similar, and moreover we can see the small bars, which in Plotly are not visible.
It’s a long time since I haven’t worked with mpl and I dont know how to use different colors for bars or a colormap. But the plot illustrates the essential: r-data do not have the same order of magnitude, and this explains why it looks different and not as we are expecting.
Ok, I see… I was actually having doubts about the gaps between the data.
Its clear to me now, I might do some data normalization, hopefully it would help.
One last question please, i’m looking for px.bar_polar argument that’s responsible on adjusting the bars angle? I would like to minimize the width of the angle in the first image of my first post, to be like the one underneath it. Is it possible?