python - 在一个绘图区域中绘制两个数据集(图表)
问题描述
我有 2 个数据框(train_df 和 test_df)。我想使用 plt.plot 函数将它们绘制在一个图中。
也希望这些数据集有不同的颜色
尝试了多种方法,但都不成功。下面的一个例子:
from matplotlib import pyplot as plt
train_df.plot(figsize=(15,8), title="Sales", color='lime')
test_df.plot(figsize=(15,8), title="Sales", color='r')
我得到 2 个不同的地块而不是一个
非常感谢您的帮助!
解决方案
这应该这样做:
ax = train_df.plot(figsize=(15,8), title="Sales", color='lime')
test_df.plot(ax=ax, figsize=(15,8), title="Sales", color='r')
推荐阅读
- r - 直方图正在跳过我的向量中的值
- google-analytics - Wix 模板通过 fileusr 向我的网站发送跟踪信息 - 导致 Google Analytics 将流量视为引荐
- android - 如何在@Provides 中注入应用程序实例?
- reactjs - 如果子属性为真,如何禁用父元素的呈现
- design-patterns - 界面粒度
- python - 如何做一个字典,用fifo进程给出输出
- reactjs - 无法创建 React 打字稿项目
- r - 在主体中创建具有可变数量变量的函数
- c++ - 在函数中将字符串转换为 char* 的问题
- mysql - 根据 mySQL 中另一个表的 AVG 值将多条记录插入到一个表中