[英]Plotly's Scatterpolar: How to change theta's range?
I'm using Plotly's scatterpolar chart to visualize several datasets.我正在使用 Plotly 的 scatterpolar 图表来可视化几个数据集。
Here's a part of my code.这是我的代码的一部分。 Below, I create the scatterpolar instance:
下面,我创建了 scatterpolar 实例:
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),
)
And here I put it in a layout:在这里我把它放在一个布局中:
fig.update_layout(
polar=dict(
radialaxis=dict(visible=True, )),
title='Dataset Statistics')
I do this for multiple data frames which allows me to easily compare them.我对多个数据框执行此操作,这使我可以轻松地比较它们。 The result is neat and looks like this:
结果很整洁,看起来像这样:
Unfortunately, it appears that the range of theta
is calculated automatically using the maximum value of r
of each scatterpolar instance.不幸的是,
theta
的范围似乎是使用每个 scatterpolar 实例的r
的最大值自动计算的。
This is not good because, to easily compare the datasets, I need theta
to be in the same range for all plots.这不好,因为为了轻松比较数据集,我需要所有图的
theta
都在同一范围内。
Question: How can I set the range of theta
to a custom value, eg, from 1 to 100?问题:如何将
theta
的范围设置为自定义值,例如从 1 到 100?
Within the radialaxis=dict(visible=True, )),
you should be able to add range=[ 1,100 ]
在
radialaxis=dict(visible=True, )),
您应该能够添加range=[ 1,100 ]
Just as an addition because it took me over an hour to figure out: if you are working with subplots, this line might be your friend:作为一个补充,因为我花了一个多小时才弄清楚:如果你正在使用子图,这条线可能是你的朋友:
fig.update_polars(radialaxis=dict(range=[0, 1]))
This will apply the range to all subplots.这会将范围应用于所有子图。 If you just call
fig.update_layout()
it will only apply the range to the first subplot.如果您只是调用
fig.update_layout()
它只会将范围应用于第一个子图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.