pythonplotlyradar-chart

plotly radar chart - I need to set some attributes


I have this code as follows;

self.fig.add_trace(go.Scatterpolar(
            r=_r, 
            theta=_theta, 
            fill="toself", 
            line=_line, 
            name=self.name))
        self.fig.update_layout(
            polar=dict(
                radialaxis=dict(
                visible=True,
                range=[0, 100],
                linecolor=black,
                gridcolor=black,
                dtick=25
                )),
            showlegend=False
            )

Which displays the following chart:

enter image description here

There are a number of things I would like to do and I cannot find how to do it. I would like to:

  1. Close the line
  2. Replace the white lines between the centre and the edge of the circle with black lines
  3. Have smaller labels and/or angle them

How do I do this, I can't find it in the docs


Solution

  • Dummy data:

    import pandas as pd
    import plotly.express as px
    
    tdf = pd.DataFrame(
        {
            "code": {0: "mo", 1: "tu", 2: "we", 3: "th", 4: "fr", 5: "sa", 6: "su"},
            "value": {0: 20.3, 1: 23.6, 2: 21.3, 3: 22.6, 4: 10.8, 5: 0.9, 6: 0.5},
        }
    )
    

    Plot code based on documentation:

    polarfig = px.line_polar(tdf, r="value", theta="code", line_close=True)  # 1. Close the line: line_close=true
    polarfig.update_polars(angularaxis_gridcolor="Black", radialaxis_gridcolor="Black") # 2. Replace the white lines
    polarfig.update_polars(angularaxis_tickfont_size=10,angularaxis_tickangle=50) # 3. Make text smaller and at an angle
    polarfig.show()
    

    enter image description here

    To add that to a trace you can do:

    fig.add_trace(polarfig.data[0])
    

    You then need to do all the update_polars calls on fig instead of polarfig.