所以,我有 2 个不同的数据集存储在 X 和 Y 中。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。我怎样才能做到这一点?
1 回答

慕运维8079593
TA贡献1876条经验 获得超5个赞
由于无论如何您都在使用熊猫,也许这是最直接的方法:
# 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)))来自定义绘图。
添加回答
举报
0/150
提交
取消