I am trying to plot a scatter plot using the .scatter method below. Here
ax.scatter(X[:,0], X[:,1], c = colors, marker = 'o', s=80, edgecolors = 'none')
with the input/args classes below:
X[:,0]] type: <class 'numpy.matrixlib.defmatrix.matrix'>
X[:,1]] type: <class 'numpy.matrixlib.defmatrix.matrix'>
colors type: <class 'list'>
however python is throwing a value error as seen here: error image
Put the thing in brackets:
plt.scatter([X[:,0]],[X[:,1]])
My experience with this is because your X
is a numpy matrix
.
Essentially, whenever you try and isolate a row from a matrix, it returns another matrix. Numpy seems to have a constraint that matrices must be 2 dimensional, so it can't tell that it's a 1-d array, and can't mask it (hence the Masked arrays must be 1-D
error)
The solution for me was to simply "cast" X
to a numpy.array
by doing:
X = np.array(X)
ax.scatter(X[:,0], X[:,1], c = colors, marker = 'o', s=80, edgecolors = 'none')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With