Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python draw path between point

Supposing I have a np.array like that:

data = np.array([[1,2],[2,4],[3,5],[4,5]])

I want to plot the path from the first point to the second then from the second to the third etc... How can I manage that. I know how to link all the point but not with a specifies order.

like image 532
Boat Avatar asked Jan 29 '23 08:01

Boat


1 Answers

import numpy as np
import matplotlib.pyplot as plt

data = np.array([[1,2],[2,4],[3,5],[4,5]])
plt.plot(data[:, 0], data[:, 1])
plt.show()

enter image description here

Alternatively, as suggested (this one by @fuglede is really nice):

plt.plot(*data.T)
like image 61
Matteo Ragni Avatar answered Jan 31 '23 21:01

Matteo Ragni