绘制连接点的线 [英] Plotting lines connecting points
问题描述
我知道还有另一个非常相似的问题,但是我无法从中提取所需的信息.
I know there is another very similar question, but I could not extract the information I need from it.
我在(x,y)
平面上有4个点:x=[x1,x2,x3,x4]
和y=[y1,y2,y3,y4]
I have 4 points in the (x,y)
plane: x=[x1,x2,x3,x4]
and y=[y1,y2,y3,y4]
x=[-1 ,0.5 ,1,-0.5]
y=[ 0.5, 1, -0.5, -1]
现在,我可以这样做来绘制四个点:
Now, I can plot the four points by doing:
import matplotlib.pyplot as plt
plt.plot(x,y, 'ro')
plt.axis('equal')
plt.show()
但是,除了四点之外,我想写两行:
But, apart from the four points, I would like to have 2 lines:
1)将(x1,y1)
与(x2,y2)
连接的一个
2)第二个连接(x3,y3)
和(x4,y4)
.
1) one connecting (x1,y1)
with (x2,y2)
and
2) the second one connecting (x3,y3)
with (x4,y4)
.
这是一个简单的玩具示例.在实际情况下,我在飞机上有2N个点.
This is a simple toy example. In the real case I have 2N points in the plane.
如何获得所需的输出:对于具有两条连接线的点?
How can I get the desired output: for points with two connecting lines ?
谢谢.
推荐答案
我认为您将需要为每个细分市场使用单独的行:
I think you're going to need separate lines for each segment:
import numpy as np
import matplotlib.pyplot as plt
x, y = np.random.random(size=(2,10))
for i in range(0, len(x), 2):
plt.plot(x[i:i+2], y[i:i+2], 'ro-')
plt.show()
(numpy
导入只是为了设置一些随机的2x10样本数据)
(The numpy
import is just to set up some random 2x10 sample data)
这篇关于绘制连接点的线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!