I want to make a radar chart for each row in a data frame,
and each chart should have 2 data traces each as a filled line (different colors)
Can I do this somehow by faceting on the timestamp I have/row, or will I need to write 2 fig.add_trace()
per chart? I’m getting the funny output with my code like below.
- trace 1 should be columns in index position 1-5 and color blue for example
- trace 2 columns 6-10 and color red
Both sets of columns have the same names due to the way the data comes in from a form, matching the categories here for each axis and label outside. My thought process was to use the column indexes.
Here’s a screenshot of what I’m getting. I’m calling the fig in a Dash component if that matters: dcc.Graph(figure=fig)
data values come from an API but basically, look like this:
values = {'Timestamp':['5/20/2022 19:44:43', '5/20/2022 20:14:36', '5/20/2022 20:14:31'],
'Design':[6, 4, 6],
'cat002':[6, 3, 6],
'cat003':[6, 6, 5],
'cat004':[6, 2, 6],
'cat005':[4, 1, 5],
'Design':[3, 6, 6],
'cat002':[4, 3, 6],
'cat003':[6, 6, 5],
'cat004':[5, 2, 6],
'cat005':[5, 6, 6]
}
# store values in dataframe
df = pd.DataFrame(values, columns=values[0])
### build the radar graph figure
categories = ['cat1','cat2','cat3','cat4','cat5']
fig = go.Figure()
fig.add_trace(go.Scatterpolar(
r=df.iloc[1:2, 1:5],
theta=categories,
fill='toself',
name='Value',
# facet_col='Timestamp'
))
fig.add_trace(go.Scatterpolar(
r=df.iloc[1:2, 6:10],
theta=categories,
fill='toself',
name='Strength',
# facet_col='Timestamp'
))
fig.update_layout(
polar=dict(
radialaxis=dict(
visible=True,
range=[0, 6]
)),
showlegend=False
)
I can make a single chart easily with the px polar options, but I’m having trouble connecting all the documentation to multiples with multiple traces. I’m still not sure which way to go after reading the polar and radar docs.