如何在matplotlib中绘制分段连续点 [英] How to plot the piecewise continuous points in matplotlib

查看:40
本文介绍了如何在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 代码来绘制点如下:

I want to know how to write the correct matplotlib code to plot the points as follows:

推荐答案

您可以根据自己拥有的三个部分拆分数据,分别对每个组进行图形绘制,然后将图形附加在一起:

You could just split up your data according to the three sections you have, graph each group separately, and then attach the graphs together:

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轴可能会使用一些额外的格式):

That will get you pretty close to what you need (though I admit some of the the x-axes could use a little extra formatting):

如果我是您,我会逐行输入该行,在每一行matplotlib代码后都点击 plt.draw(),以查看发生了什么.

If I were you I would enter that line by line, hitting plt.draw() after every line of matplotlib code to see what exactly is going on.

这篇关于如何在matplotlib中绘制分段连续点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆