在matplotlib scatter3d中设置zlim

Jan*_*ann 10 matplotlib scatter3d

我在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()
Run Code Online (Sandbox Code Playgroud)

plt.xlim()plt.ylim()做工精细,但我没有找到一个函数来设置的边框z方向.我怎么能这样做?

Bar*_*art 13

只需使用对象的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)
Run Code Online (Sandbox Code Playgroud)

  • 为什么 `plt.zlim` 没有实现?这将使 mpl 更加一致,人们不必在这里问这个问题。 (8认同)