因此,我在X和Y中存储了2个不同的数据集。
x = df1['Sales']
y = df2['Sales']
我正在使用以下代码绘制它们
plt.figure(figsize = (15,7))
plt.subplot(1, 2, 1)
x.plot(kind='box')
plt.subplot(1, 2, 2)
y.plot(kind='box')
他将它们并排绘制,但是我需要它在同一盒图上绘制2个不同的DataFrame。
我该怎么做?
答案 0 :(得分:2)
由于您还是在使用熊猫,也许这是最简单的方法:
# put both series in one dataframe
df = pd.concat([df1['Sales'], df2['Sales']], axis=1)
# set column names (will be displayed as plot labels)
df.columns = ['x Sales', 'y Sales']
# use pandas' boxplot method
df.boxplot()
您仍然可以使用所有常用的matplotlib命令(例如plt.figure(figsize = (15,7))
)来自定义图表。