python - 在一张图中绘制两个数据框
问题描述
我有这两个数据框 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)
推荐阅读
- ubuntu - Nginx服务启动失败原因:start-limit-hit'
- javascript - 具有别名的本地 npm 依赖项
- docker - 无法在 cumulocity 上部署微服务
- c# - 从 Azure 存储中删除 Blob 失败
- encryption - 数据源的安全加载错误。解密数据时出错
- jenkins - 'Jenkinsfile' 未找到
- java - Fisica.init() 不被自己的库识别
- laravel-5 - Laravel 5.6 使用谷歌登录在本地主机中工作,但在主机中不起作用
- javascript - 正则表达式只显示一个结果我怎样才能让它在 JavaScript 中显示其余结果
- r - 将特殊字符保存在词频矩阵中