outlying data points are still being plotted after enforcing axes in matplotlib scatter3D?
I'm just starting to learn python, and was recently trying to make a 3D scatter plot with my dataset using matplotlib. Because my data is so spread out (x range = (1 to 20000)), I tried to enforce the X-axis limits to show just data points where x < 1000. However, when I try to set axis limits, I still see points that are greater than x=1000 on the plot. I can't really fig开发者_JAVA百科ure out why it's doing it, and couldn't find an answer by my searches on the internet :(
This is kind of a simplified example of what I did... When I enforce x-axis limits to 2, I still see the point (3,3,3) being plotted. Why is it doing this and what am I doing wrong?
THANK YOU VERY MUCH in advance!!!!
from matplotlib.figure import Figure
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
xs = [1,2,3,5,11]
ys = [1,2,3,4,5]
zs = [1,2,3,4,5]
ax.scatter3D(xs, ys, zs, c="blue")
ax.set_xlim3d([0,2])
ax.set_ylim3d([0,5])
ax.set_zlim3d([0,5])
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
The following works well for me. You just had a minor bug in the set_xlim3d call. Take a look here for more documentation.
from matplotlib.figure import Figure
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
xs = [1,2,3,5,11]
ys = [1,2,3,4,5]
zs = [1,2,3,4,5]
ax.scatter(xs, ys, zs, c="blue")
ax.set_xlim3d(0,2)
ax.set_ylim3d(0,5)
ax.set_zlim3d(0,5)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
精彩评论