Issue
I know there is another very similar question, but I could not extract the information I need from it.
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) one connecting (x1,y1)
with (x2,y2)
and
2) the second one connecting (x3,y3)
with (x4,y4)
.
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 ?
Thank you.
Solution
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()
(The numpy
import is just to set up some random 2x10 sample data)
Answered By - xnx
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.