3

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.

sawyermclane
  • 896
  • 11
  • 28

2 Answers2

3

The voxels method has been introduced in matplotlib 2.1.

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

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • Thanks. I found I was using pip for a different python environment to try and update matplotlib. I had to use conda to update it. However, I am curious, I found this (https://github.com/matplotlib/matplotlib/issues/9745) issue where he was able to get voxels using version 1.5.3. How is this possible? – sawyermclane Jun 01 '18 at 16:39
  • 1
    It is not possible. That needs to be a mistake by the person writing the issue. – ImportanceOfBeingErnest Jun 01 '18 at 16:44
1

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

Jay Calamari
  • 573
  • 4
  • 17