Radar chart - fill between based on a condition

Dear all,

I am trying to create a radar chart with colouring based on a condition.
I am taking inspiration from this post on StackOverflow but couldn’t implement it properly.
The condition shown here is a color property based on ‘res’: [red < 0 < green].
Below, I add a code snippet of what worked so far with ‘fillcolor’, and a possible expected result.

import plotly.graph_objects as go
import plotly.io as pio
pio.templates.default = "plotly_white"


r=[0, 0, 0, 0, 0, 0]
theta=['Property 1', 'Property 2', 'Property 3', 'Property 4', 'Property 5', 'Property 6', 'Property 1'] 
res = [0.5, 0.5, 0.5, -0.5, -0.5, -0.5, 0.5]
color_s = 'rgba(125, 125, 125, 0.4)'

fig = go.Figure()
fig.add_trace(go.Scatterpolar(r=[0, 0, 0, 0, 0, 0, 0], theta=theta, fill=None, name='T-Score'))
fig.add_trace(go.Scatterpolar(r=res, theta=theta, fill='tonext', line_color=color_s, fillcolor=color_s, name='Data'))
fig.update_layout(polar=dict(radialaxis=dict(visible=True, range=[-1, 1])), width=500, height=500, title_text="Radar chat with color", title_x=0.5)
fig.update_traces()
fig.show()

Current result:
RadarNoColor

Expected result:
RadarChartColor

Any help or workaround would be much appreciated!
Best,
Simone

Hi @simone_p,
To assign different colors to the two regions, some computations are needed, but with your settings they are impossible, because in mathematics the polar radius cannot be negative. If you reference all points involved in your figure to a polar system with origin at 0, i.e. with the following code:

import plotly.graph_objects as go

color_s = 'rgba(125, 125, 125, 0.4)'
fig = go.Figure()
fig.update_layout(polar=dict(radialaxis=dict(visible=True, range=[0, 2])), 
                  template="plotly_white",
                  width=450, height=450#, title_text="Radar chart with color", title_x=0.5
                 )
theta=['Property 2', 'Property 3', 'Property 4', 'Property 5', 'Property 6', 'Property 1'] 
fig.add_trace(go.Scatterpolar(r=[1]*7, theta=theta, fill=None, name='T-Score'))
res= [1.5, 1.5, 1.5, 0.5, 0.5, 0.5, 1.5]
fig.add_trace(go.Scatterpolar(r=res, theta=theta, fill='tonext',
                              line_color=color_s, fillcolor=color_s, name='Data'))

twopolar_charts

then I can help you. Does radius =-0.5 have a meaning in the context of your data?
Please explain what your points represent, to understand why you considered such odd polar coordinates, with center at -1, and radius 0!!! From mathematical point of view this is a non-sense and no computations can be performed. The example posted on stackoverflow is a numerical one, and the comparisons can be performed, but not in your case, where theta is a categorical variable, and radii are some 0, other negative or positive.