Issue
Normally the x and y input values are merged into a coordinate point. Using list, it's ok:
import matplotlib.pyplot as plt
import numpy as np
a = [5,6]
plt.scatter(a[0],a[1])
plt.show() # shows one point at 5,6. OK
Using numpy with same values in x and y:
b=np.array([[4],[4]])
plt.scatter(b[:,0],b[:,0])
plt.show() # shows one point at 4,4. OK
But using numpy with different values in x and y:
c=np.array([[5],[6]])
plt.scatter(c[:,0],c[:,0])
plt.show() # shows points at 5,5 and 6,6. Problem
Solution
With the column vector for c
, calling c[:,0]
gives:
print(c[:,0]) # array([5, 6])
When creating a scatterplot, the first argument gives the x-values and the second gives the y-values. So, you are setting the x-values to be [5, 6]
and your y-values to be [5, 6]
. The points are plotted matching one-to-one. Therefore, the first values of x and y are [5, 5]
and the second values are [6, 6]
, hence the plot results.
To get a single point at (5, 6)
, you do what you did with a
, namely,
plt.scatter(c[0], c[1])
Answered By - jared
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.