26

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

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()andplt.ylim()工作正常,但我没有找到在 z 方向设置边框的功能。我该怎么做?

4

1 回答 1

37

只需使用对象的set_zlim功能axes(就像您已经使用的那样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)
于 2016-05-30T09:34:27.840 回答