排列数据以便在 Plotly 中使用玫瑰图 [英] Arrange data in order to use rose diagram with Plotly
问题描述
我试图用 Plotly 绘制风玫瑰图.这是我从网上找到的代码,它运行良好.
I tried to plot the wind rose diagram with Plotly. Here is the code I found from the web and it works perfectly.
import plotly.express as px
df = px.data.wind()
fig = px.bar_polar(df, r="frequency", theta="direction",
color="strength", template="plotly_dark",
color_discrete_sequence= px.colors.sequential.Plasma_r)
fig.show()
这是输出.
但我的数据格式与所需的不同.所需的格式是方向(西、东-西等)、强度(例如:级别 1 到 6)和频率(此处为我附上了数据框的一部分).
But my data format is different from the required one. The required format is a direction(west,east-west, etc), strength(ex:level 1 to 6) and frequency(here I attached some part of the data frame).
但是我的数据集有大约 80,000 个不同时间点的数据点.(我没有频率栏,我有不同时间点的方向和强度).如何将我的数据转换为频率(在这里我附上了我的数据框的一部分)
But my dataset has around 80,000 data points for different time points. (I don't have frequency column and I have direction and strength for different time points). How do I convert my data to make frequency (here I attached some part of my data frame)
推荐答案
假设你有这样的数据:
grp = df.groupby(["Direction","Strength"]).size()\
.reset_index(name="frequency")
输出为:
这篇关于排列数据以便在 Plotly 中使用玫瑰图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!