Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Axes3DSubplot' object has no attribute 'voxels'

I'm trying to use matplotlib to display some 3d perlin noise. I have read that the voxels method from Axes3DSubplot could be used to simply display values. However, when I try and call ax.voxels(voxels, facecolors=colors, edgecolor='k'), it throws the exception AttributeError: 'Axes3DSubplot' object has no attribute 'voxels'. Here is my code:

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()

My python version is 3.6.2 (Anaconda 64-bit). My matplotlib version is 2.0.2. I have used both the ipynb (module://backend_interagg) and Qt5Agg backends, which both give the same problem. I'm running Windows 10.

like image 600
watersnake Avatar asked Mar 11 '26 11:03

watersnake


2 Answers

The voxels method has been introduced in matplotlib 2.1.

Any earlier version of matplotlib does not have this method available.

like image 193
ImportanceOfBeingErnest Avatar answered Mar 13 '26 00:03

ImportanceOfBeingErnest


works for me, python 3.6.4, anaconda 5.1.0 and matplotlib 2.2.2 in pycharm.

it shows this: your code shows this

like image 38
Jay Calamari Avatar answered Mar 13 '26 02:03

Jay Calamari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!