我正在尝试使用 matplotlib 来显示一些 3d 柏林噪声。我读过 voxels
中的 Axes3DSubplot
方法可用于简单地显示值。但是,当我尝试调用 ax.voxels(voxels, facecolors=colors, edgecolor='k')
时,它会抛出异常 AttributeError: 'Axes3DSubplot' object has no attribute 'voxels'
。这是我的代码:
import noise
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x, y, z = np.indices((8,8,8))
voxels = np.zeros((8,8,8), dtype=np.bool)
for xp in range(8):
for yp in range(8):
for zp in range(8):
voxels[xp,yp,zp] = True if abs(noise.pnoise3(xp/8,yp/8,zp/8)) > 0.5 else False
colors = np.empty(voxels.shape, dtype=object)
colors[voxels] = 'green'
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.voxels(voxels, facecolors=colors, edgecolor='k') #EXCEPTION
plt.show()
我的 python 版本是 3.6.2(Anaconda 64 位)。我的 matplotlib 版本是 2.0.2。我使用了 ipynb (
module://backend_interagg
) 和 Qt5Agg
后端,它们都出现了同样的问题。我正在运行 Windows 10。 最佳答案
voxels
方法 has been introduced in matplotlib 2.1 。
任何早期版本的 matplotlib 都没有此方法可用。
关于python - 'Axes3DSubplot' 对象没有属性 'voxels',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50635610/