Boat
Boat

Reputation: 529

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.

Upvotes: 5

Views: 12027

Answers (1)

Matteo Ragni
Matteo Ragni

Reputation: 2956

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)

Upvotes: 8

Related Questions