Reputation: 64
I want to print a scatter plot of points and to add their major directions.
So I have an array of vectors (in 3D) [x,y,z] to [ u,v,w] that I want to display and another array of points in 3D.
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.quiver(x, y, z, u, v, w, length=0.1, normalize=False)
# if i stop here I see the quiver
ax.scatter(X[:, 0], X[:, 1], X[:, 2])
plt.show() # here I see only the scatter
Upvotes: 0
Views: 1560
Reputation: 2402
The mplot3d
library is a simple plotting which mocks the shape of 3d plots rather than actually draw them. As a result you cannot have two clear plots in the same axes. You can see this clearly by plotting two surfaces, shifted slightly to one side. It plots one of them then plots the other one, so the depth will be all messed up.
Saying that, this doesn't seem to be the problem with you. You haven't provided any information about your data, but for a dummy case I made, the plot seems reasonable:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure();ax = fig.gca(projection='3d')
ax.quiver([0,0,0], [0,0,0], [0,0,0], [5,0,0], [0,5,0], [0,0,5], length=0.1, normalize=False)
ax.scatter([0,1,2,3], [1,2,1,2],[-1,0,1,2])
Try this code and see if you get the same results or not?
It might be that your quiver plot is much smaller than the range of the scatter plot, so you're missing it visually.
Upvotes: 2