gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 14:44:41 25 4
gpt4 key购买 nike

我正在尝试使用 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。

最佳答案

体素 方法 has been introduced in matplotlib 2.1 .

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

关于python - 'Axes3DSubplot' 对象没有属性 'voxels',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50635610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com