You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Plotly Scatterpolar图表:如何自定义Theta轴的范围?

How to set a custom radial axis range for Plotly Scatterpolar charts

Problem Description

I'm using Plotly's scatterpolar chart to visualize multiple datasets. Here's a snippet of my code:

Creating the scatterpolar trace:

go.Scatterpolar(
    r=[dataset_dataframe['word_count'].median(), 
       dataset_dataframe['char_count'].median(), 
       dataset_dataframe['capitals'].median(), 
       dataset_dataframe['num_exclamation_marks'].median(), 
       dataset_dataframe['num_punctuation'].median()],
    name=dataset_name,
    theta=['No. of Words', 'No. of Characters', 'No. of Capitals', 'No. of Exclamation Marks', 'No. of Punctuations'],
    fill='toself',
    line=dict(color='brown'),
    subplot=subplot_name
)

Layout configuration:

fig.update_layout(
    polar=dict(
        radialaxis=dict(
            visible=True,
        )
    ),
    title='Dataset Statistics'
)

This setup lets me compare multiple datasets, but I noticed the radial axis (r-axis) range is automatically calculated based on the maximum r-value of each scatterpolar trace. This makes it hard to compare datasets side by side. How can I set a custom fixed range (like 1 to 100) for the radial axis?


Solution

Hey, this is a quick fix! You just need to add the range parameter to the radialaxis configuration in your layout.

Basic Single Polar Plot

Modify your layout code to explicitly define the radial axis range:

fig.update_layout(
    polar=dict(
        radialaxis=dict(
            visible=True,
            range=[1, 100]  # Your custom min and max values here
        )
    ),
    title='Dataset Statistics'
)

For Subplots

If you're using multiple polar subplots (like polar1, polar2, etc.), you'll need to set the range for each subplot's radial axis individually to keep them consistent:

fig.update_layout(
    polar1=dict(
        radialaxis=dict(
            visible=True,
            range=[1, 100]
        )
    ),
    polar2=dict(
        radialaxis=dict(
            visible=True,
            range=[1, 100]
        )
    ),
    title='Dataset Statistics'
)

This will lock all radial axes to your specified 1-100 range, making it much easier to compare metrics across different datasets at a glance.


内容的提问来源于stack exchange,提问作者Aventinus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 09:52:39