Jo-Achna
Jo-Achna

Reputation: 315

Display data points on radar plot in plotly

I cannot find an answer on how to display the data points (see r indicated in go.Scatterpolar). Maybe someone has an idea how to achieve that?

Additionally, the numbers from 0-5 are oddly rotated, and I cannot find a way on how to fix it. Any hints, comments, and suggestions would be highly appreciated.

This is a dummy code:

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = go.Figure()

question= ["Q1", "Q2","Q3", "Q4"]

fig = make_subplots(rows=2, cols=2, specs=[[{'type': 'polar'}] * 2] * 2)

fig.add_trace(
    go.Scatterpolar(
        theta= question, #question
        r=[5.60, 5.62, 5.60, 5.59], 
        name = "Graph 1"
    ),
    row=1,
    col=1,
)
    
fig.add_trace(
    go.Scatterpolar(
        theta= question, #question
        r=[5.60, 5.62, 5.60, 5.59], 
        name = "Graph2"
    ),
    row=1,
    col=2,
)
fig.add_trace(
    go.Scatterpolar(
        theta= question, #question
        r=[5.60, 5.62, 5.60, 5.59], 
        name = "Graph3"
    ),
    row=2,
    col=1,
)
    
fig.add_trace(
    go.Scatterpolar(
        theta= question, #question
        r=[5.60, 5.62, 5.60, 5.59],
        name = "Graph4"
    ),
    row=2,
    col=2,
)


Here is the radar graph in plotly:

enter image description here

Ideally I would like to have an elegant way of showing the values outside the graph, so that it is not cluttered. See my poor attempt in Paint below. If that doesn't work, anything else is also fine

enter image description here

Upvotes: 0

Views: 1295

Answers (1)

r-beginners
r-beginners

Reputation: 35205

Scatter plots in polar coordinates are the same as regular scatter plots and have a mode so that they can be displayed by setting the line and string. The string is positioned at the center of the top. To adjust the scale at that time, set the axis range in the layout update.

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = go.Figure()

question= ["Q1", "Q2","Q3", "Q4"]

fig = make_subplots(rows=2, cols=2, specs=[[{'type': 'polar'}] * 2] * 2)

fig.add_trace(
    go.Scatterpolar(
        mode='lines+text',
        theta= question, #question
        r=[5.60, 5.62, 5.60, 5.59], 
        name = "Graph 1",
        text=[5.60, 5.62, 5.60, 5.59],
        textposition='top center'
    ),
    row=1,
    col=1,
)
    
fig.add_trace(
    go.Scatterpolar(
        mode='lines+text',
        theta= question, #question
        r=[5.60, 5.62, 5.60, 5.59], 
        name = "Graph2",
        text=[5.60, 5.62, 5.60, 5.59],
        textposition='top center'
    ),
    row=1,
    col=2,
)
fig.add_trace(
    go.Scatterpolar(
        mode='lines+text',
        theta= question, #question
        r=[5.60, 5.62, 5.60, 5.59], 
        name = "Graph3",
        text=[5.60, 5.62, 5.60, 5.59],
        textposition='top center'
    ),
    row=2,
    col=1,
)
    
fig.add_trace(
    go.Scatterpolar(
        mode='lines+text',
        theta= question, #question
        r=[5.60, 5.62, 5.60, 5.59],
        name = "Graph4",
        text=[5.60, 5.62, 5.60, 5.59],
        textposition='top center'
    ),
    row=2,
    col=2,
)

fig.update_layout(autosize=False,
                  height=600,
                  polar=dict(radialaxis=dict(range=[0,6])),
                  polar2=dict(radialaxis=dict(range=[0,6])),
                  polar3=dict(radialaxis=dict(range=[0,6])),
                  polar4=dict(radialaxis=dict(range=[0,6])),
)
fig.show()

enter image description here

Upvotes: 1

Related Questions