1

I am trying to plot a scatter plot using mplot3d but the scatter method gives me value error: 'xs' and 'ys' must be of the same size. When I print their types and sizes, they appear perfect. I am unable to figure out whats wrong.

Here is the part of my code :
'mat2' is 512 X 4 matrix that is already computed.

mat2 = np.array(mat2)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
co = []

xx = mat2[:,:1]
yy = mat2[:,:2]
z = mat2[:,:3]
co = mat2[:,:4]

#printing the size and types of the arguments to the scatter()
print(str(len(xx))+str(type(xx))+' '+str(len(yy))+str(type(yy))+' '+str(len(z))+' '+str(len(co)))

ax.scatter(np.array(xx), np.array(yy), z=np.array(z), c=np.array(co), cmap=plt.hot())

Here is a screenshot of the output that I get - ValueError Screenshot

Any help ?

AlMikFox
  • 13
  • 3

1 Answers1

0

xx and yy are not the same size. Instead of printing the length, you need to print the shape.

print(xx.shape)

You will observe that xx is of shape (512, 1) and yy is of shape (512,2). Therefore yy has two columns and thus twice as many entries as xx.

Since it seems that you want to plot a scatter of the second column of mat2 against the first, you should create xx and yy as such:

xx = mat2[:,0]
yy = mat2[:,1]

The same is of course true for the other arrays z and co.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712