在一个图中绘制两个数据帧



我有两个数据帧df和df1

B2B_1 = {'Month': ['10/2018','11/2018','12/2018','01/2019','02/2019','03/2019'],
'B2B': [200,400, 250,
100,120,200]]
}
B2C_1 = {'Month': ['10/2018','11/2018','12/2018','01/2019','02/2019','03/2019'],
'B2C': [200,400, 250,
100,120,200]
}
df=pd.DataFrame(B2B_1)
df1=pd.DataFrame(B2C_1)

我不知道如何将这两个数据帧绘制在一个图中,轴是基于"月">

pandas绘图函数中有ax参数;如果你传递一个例如matplotlib轴实例给它,它将在该轴上进行绘图。所以

# make a figure and an axis 
fig, ax = plt.subplots(figsize=(14, 7))
# plot desired quantities; note the `ax=ax` in both
df.plot(x="Month", y="B2B", ax=ax)
df1.plot(x="Month", y="B2C", ax=ax)

两个DataFrame类似于下面的代码

B2B_1 = {'Month': ['10/2018','11/2018','12/2018','01/2019','02/2019','03/2019'],
'B2B': [200,400, 250,
100,120,200]
}
B2C_1 = {'Month': ['10/2018','11/2018','12/2018','01/2019','02/2019','03/2019'],
'B2C': [200,400, 250,
100,120,200]
}

df=pd.DataFrame(B2B_1)
df1=pd.DataFrame(B2C_1)
x=df['Month']
x1=df["B2B"]
y=df1['Month']
y1=df1["B2C"]  
plt.figure(figsize=(15,8))
plt.bar(x,x1,label="Month")
plt.bar(y,y1,label="Month")
plt.title("Data")
plt.legend(title="Data")
plt.show()

使用该代码可以轻松绘制两个数据框