【问题标题】:Box and Whisker Plot with three bins per point箱须图,每点三个箱
【发布时间】:2021-06-15 03:50:32
【问题描述】:

我有三个数据集,我想按月绘制箱形图。目前我正在制作三个独立的地块,但我很想将它们堆叠起来!

df=pd.read_csv('data.csv',parse_dates=['time'],  sep=',').dropna()
df['time'] = pd.to_datetime(df['time']).dropna()
df['month'] = df['time'].dt.strftime('%b').dropna()
df.reset_index(inplace=True)


df1 = df[["month", "data1" ]]
df2 = df[["month", "data2" ]]
df3 = df[["month", "data3" ]]

所以是这样的:(但是让每个数据集都有不同的颜色,比如红色、蓝色、绿色,并且每一步都有 ea.other 的 bin 偏移量,所以一月等三个图)

fig, ax = plt.subplots()
fig.set_size_inches((24,8))
sns.boxplot(x= 'month',y= 'ssa_R',data=df2,ax=ax)

plt.show()
plt.rcParams.update({'font.size': 18})

【问题讨论】:

    标签: python-3.x pandas matplotlib seaborn boxplot


    【解决方案1】:

    尝试:

    sns.boxplot(data=df[["month", "data1", "data2", "data3" ]]
                       .melt('month', var_name='dataset',value_name='data'), 
                x='month', y='data', hue='dataset')
    

    你会得到这样的东西:

    【讨论】:

      猜你喜欢
      • 2019-04-23
      • 2021-09-08
      • 2018-07-20
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      相关资源
      最近更新 更多