首页 > 解决方案 > 在一个绘图区域中绘制两个数据集(图表)

问题描述

我有 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 个不同的地块而不是一个

非常感谢您的帮助!

标签: pythonmatplotlibplotcolors

解决方案


这应该这样做:

ax = train_df.plot(figsize=(15,8), title="Sales", color='lime')
test_df.plot(ax=ax, figsize=(15,8), title="Sales", color='r')

推荐阅读