我正在尝试使用 matplotlib 来显示一些 3d perlin 噪声。我已经读过voxels
from 的方法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。