Reputation: 3359
What I have is a numpy array that looks like the following.
>>> result
array([[ 0. , 0. ],
[ 18.6, -11.1],
[ 36.1, -21.9],
...,
[ -535.5, 1020.3],
[ -535.5, 1020.3],
[ -535.5, 1020.3]])
And what I'm trying to do is plot it using matplotlib.pyplot as plt
with the first number on the x axis and the second number on the y axis. How do I do that?
Upvotes: 1
Views: 397
Reputation: 3363
You could do
import matplotlib.pyplot as plt
plt.plot(*result.T)
The *
is a fancy way of unpacking a list, see here.
Upvotes: 2
Reputation: 11063
You can get slices of numpy arrays like so:
import numpy as np
a = np.array([[0, 1], [2, 3], [4, 5]])
>>> a
array([[0, 1],
[2, 3],
[4, 5]])
>>> a[:,0]
array([0, 2, 4])
>>> a[:,1]
array([1, 3, 5])
So if the first column has your x values, and the second has your y values, you would plot like:
import matplotlib.pyplot as plt
plt.plot(a[:, 0], a[:, 1])
plt.show()
Upvotes: 1