Box and Whisker Plot with three bins per point

Viewed 66

I have three datasets I want to plot box plots for on monthly intervals. Currently I am making three separate plots but would love to stack them!

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" ]]

so something like this:( but have each dataset a different color say red, blue, green, and have the bins offset of ea. other per step so three plots for the month of Jan etc)

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

enter image description here

1 Answers

Try with:

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

You would get something like this:

enter image description here

Related