如何在一个图中同时绘制三个图?

时间:2020-05-01 17:41:20

标签: python matplotlib

我想在1张图中绘制3个数据集,以便可以对其进行比较。

div

请帮助。

1 个答案:

答案 0 :(得分:0)

有关可以使用df.plot()设置哪些参数的信息,请参见文档here

您需要创建3个子图,并绘制到这些子图上。例如,一种执行此操作的方法:

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(12,4)) #create a figure with a 12 width, 4 length

ax1 = plt.subplot(131) #subplot with 1 row, 3 columns the 1st one
ax2 = plt.subplot(132) #subplot with 1 row, 3 columns the 2nd one
ax3 = plt.subplot(133) #subplot with 1 row, 3 columns the 3rd one


dataset2.plot(kind='scatter',x='time',y='Temp',ax=ax1)
dataset27.plot(kind='scatter',x='teime1',y='Temp1',ax=ax2)
dataset28.plot(kind='scatter',x='time2',y='Temp2',ax=ax3)

plt.show()

要相互绘制它们:

ax = plt.subplot(111) #1 subplot

dataset2.plot(kind='scatter',x='time',y='Temp',ax=ax)
dataset27.plot(kind='scatter',x='teime1',y='Temp1',ax=ax)
dataset28.plot(kind='scatter',x='time2',y='Temp2',ax=ax)