如何更改每个 plotly scatterpolar 类别的 theta 范围

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

我目前正在使用 Plotly 的 scatterpolar 模块来创建雷达图。我正在尝试可视化所有 5 项篮球统计数据(得分、助攻、篮板、抢断和盖帽)的统计类别。问题是每个类别的范围都设置为最高值,即点数。我想将每个类别的范围分开(例如:得分范围是 0 到 50,助攻范围是 0 到 15,抢断范围是 0 到 5 等)。

如您所见,整个图表都偏向点类别。

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()

这是我现在的代码。

一个选项是缩放每个类别,然后设置范围 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()