如何在matplotlib中绘制分段连续点

时间:2015-03-25 12:56:45

标签: python matplotlib

我的数据集如下:

G R Y
1 1 0
1 2 1
1 3 2
1 4 4
1 5 2
2 1 1
2 2 2
2 3 3
2 4 2
3 1 0
3 2 1
3 3 2
3 4 2
3 5 3

我想知道如何编写正确的matplotlib代码来绘制点,如下所示:

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以根据您拥有的三个部分拆分数据,分别绘制每个图表,然后将图表附加在一起:

fig, axes = plt.subplots(1, 3, sharey=True)
Y = [0, 1, 2, 4, 2, 1, 2, 3, 2, 0, 1, 2, 2, 3]
Y0 = Y[0:6]
Y1 = Y[5:10]
Y2 = Y[9:15]
axes[0].plot(Y0)
axes[1].plot(Y1)
axes[2].plot(Y2)
plt.ylim([0, 5])
subplots_adjust(wspace=0)

这会让你非常接近你需要的东西(虽然我承认一些x轴可能会使用一些额外的格式):

enter image description here

如果我是你,我会逐行输入,在每行matplotlib代码后点击plt.draw(),看看到底发生了什么。