首页 > 解决方案 > 如何在一个图中同时绘制 3 个图?

问题描述

我想在 1 个图中绘制 3 个数据集,以便我可以比较它们。

dataset2.plot(kind='scatter',x='time',y='Temp')

dataset27.plot(kind='scatter',x='teime1',y='Temp1')

dataset28.plot(kind='scatter',x='time2',y='Temp2')

请帮忙。

标签: pythonmatplotlib

解决方案


请参阅此处的文档,了解您可以设置哪些参数df.plot()

您需要创建 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)

推荐阅读