title: What is the most efficient way to plot 3d array in Python?
body: <p>What is the most efficient way to plot 3d array in Python?</p>
  
  <p>For example:</p>
  
  <pre><code>volume = np.random.rand(512, 512, 512)
  </code></pre>
  
  <p>where array items represent grayscale color of each pixel.</p>
  
  <hr>
  
  <p>The following code works too slow:</p>
  
  <pre><code>import matplotlib as mpl
  from mpl_toolkits.mplot3d import Axes3D
  import numpy as np
  import matplotlib.pyplot as plt
  
  fig = plt.figure()
  ax = fig.gca(projection='3d')
  volume = np.random.rand(20, 20, 20)
  for x in range(len(volume[:, 0, 0])):
      for y in range(len(volume[0, :, 0])):
          for z in range(len(volume[0, 0, :])):
              ax.scatter(x, y, z, c = tuple([volume[x, y, z], volume[x, y, z], volume[x, y, z], 1]))
  plt.show()
  </code></pre>