多线折线图matplotlib

时间:2017-01-12 19:18:02

标签: python csv plot graph line

我试图将3个相同类型的数据集绘制到一个具有三条不同线的线图上。所有数据集共享相同的x类型,' time'和y型,'测量'。但是,每个数据集中的x和y类型的每个数据集的长度都不同。我如何使用matplotlib创建三线折线图?

每个数据集都是从csv文件中提取的,最后以列表的形式结束。这适用于每个数据集的x和y分量。以下是我收集数据的方式:

# Data Set 1
with open('File1.csv', 'r') as f:
     data_1 = list(reader(f))

measurement_1 = [i[3] for i in data_1[1::]]
time_1 = [parser.parse(i[0]) for i in data_1[1::]]

measurement_1, time_1 = zip(*[(i, j) for i, j in zip(measurement_1, time_1) if i !=''])

measurement_1 = list(measurement_1)
time_1 = list(time_1)

# Data Set 2
with open('File2.csv', 'r') as f:
     data_2 = list(reader(f))

measurement_2 = [i[3] for i in data_2[1::]]
time_2 = [parser.parse(i[0]) for i in data_2[1::]]

measurement_2, time_2 = zip(*[(i, j) for i, j in zip(measurement_2, time_2) if i !=''])

measurement_2 = list(measurement_2)
time_2 = list(time_2)

# Data Set 3
with open('File3.csv', 'r') as f:
     data_3 = list(reader(f))

measurement_3 = [i[3] for i in data_3[1::]]
time_3 = [parser.parse(i[0]) for i in data_3[1::]]

measurement_3, time_3 = zip(*[(i, j) for i, j in zip(measurement_3, time_3) if i !=''])

measurement_3 = list(measurement_3)
time_3 = list(time_3)

1 个答案:

答案 0 :(得分:0)

由于您尚未提供参考数据框,因此这是一个广泛的框架。

ax = df.plot()
df2.plot(ax = ax)
df3.plot(ax = ax)

plt.show()