'Axes3DSubplot' 对象没有属性 'voxels'

'Axes3DSubplot' object has no attribute 'voxels'

我正在尝试使用 matplotlib 显示一些 3d 柏林噪声。我读到 Axes3DSubplot 中的 voxels 方法可用于简单地显示值。但是,当我尝试调用 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.

适用于我,python 3.6.4、anaconda 5.1.0 和 matplotlib 2.2.2 pycharm。

它显​​示了这个:

voxels方法has been introduced in matplotlib 2.1

任何早期版本的 matplotlib 都没有此方法。