2016-05-30 848 views
3

我有三个列表xs,ys,zs的Python中的数据点,我正尝试使用scatter3d方法创建一个使用matplotlib的3d图。在matplotlib中设置zlim scatter3d

import matplotlib.pyplot as plt 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
plt.xlim(290) 
plt.ylim(301) 
ax.set_xlabel('X') 
ax.set_ylabel('Y') 
ax.set_zlabel('Z') 
ax.scatter(xs, ys, zs) 
plt.savefig('dateiname.png') 
plt.close() 

plt.xlim()plt.ylim()做工精细,但我没有找到一个功能设置的边界在z方向。我该怎么做?

回答

5

只需使用axes对象的set_zlim功能(像你已经有set_zlabel,这也不能作为plt.zlabel一样):

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 
import numpy as np 

xs = np.random.random(10) 
ys = np.random.random(10) 
zs = np.random.random(10) 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
ax.set_xlabel('X') 
ax.set_ylabel('Y') 
ax.set_zlabel('Z') 
ax.scatter(xs, ys, zs) 
ax.set_zlim(-10,10) 
+0

非常感谢您!这正是我所期待的。 – goethin