在一个绘图区域中绘制两个数据集(图形)

2024-05-20 02:04:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我有2个数据帧(train\u df和test\u df)。我想用plt.绘图功能。你知道吗

也希望这些数据集有不同的颜色

尝试了多种方法,但没有成功。下面是一个例子:

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')

我得到两个不同的情节而不是一个

非常感谢你的帮助!你知道吗


Tags: 数据方法test功能绘图dfplottitle
2条回答

这应该做到:

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

你可以这样做:

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

相关问题 更多 >