Skip to content
Advertisement

How to change the range of theta for each plotly scatterpolar category

I am currently using Plotly’s scatterpolar module to create a radar chart. I am trying to visualize the statistical categories for all 5 basketball statistics (points, assists, rebounds, steals, and blocks). The problem is that the range for every single category is set to the highest value which is points. I’d like to make the range for each category separate (for example: the range for points is 0 to 50, the range for assists to be 0 to 15, the range of steals to be 0 to 5,etc.).

This is what is looks like right now.

As you can see the entire chart is skewed towards the point category.

categories = ['Points', 'Assists', 'Rebounds', 'Steals', 'Blocks']
all_averages = [avg_points, avg_assists, avg_rebounds, avg_steals, avg_blocks]

trace = go.Scatterpolar(r = all_averages, theta = categories, fill = 'toself', name = f'{first} {last}')
data = [trace]
figure = go.Figure(data = data, layout = layout)
figure.show()

This is the code I have right now.

Advertisement

Answer

One option is to scale each category then set the range 0-1.

import plotly.graph_objects as go

first = 'John'
last = 'Doe'

range_pts = 50
range_ast = 15
range_rbs = 20
range_stl = 5
range_blk = 5

ranges = [range_pts, range_ast, range_rbs, range_stl, range_blk]

categories = [f'Points ({range_pts})', f'Assists ({range_ast})', f'Rebounds ({range_rbs})', f'Steals ({range_stl})', f'Blocks ({range_blk})']
all_averages = [26, 7, 11, 2, 1]

for idx, value in enumerate(ranges):
    all_averages[idx] = all_averages[idx]/ranges[idx]


trace = go.Scatterpolar(r = all_averages, theta = categories, fill = 'toself', name = f'{first} {last}')
data = [trace]
figure = go.Figure(data = data, layout = None)
figure.update_polars(radialaxis=dict(visible=False,range=[0, 1]))
figure.show()

enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement