title: How to plot a 3d scatterplot with the color determined from another variable?
body: <p>I made a 3d scatterplot that displays the position of galaxies in a cluster (basically like the latitude and longitude) as a function of their velocity.  However, I've been asked to make the color of the data points be determined by another variable, h in the code.  The purpose of the variable isn't important to know, but that in my actual code, every data point is determined from 4 arrays.  After spending a long time looking up how to do this, I finally (almost) have it.  The only problem is that when I plot it, the colors of the dots change as soon as I move the plot around to see it from a different direction.  Also, I've been having issues trying to display a colorbar.</p>
  
  <pre><code>import pylab as p
  import numpy as np
  from mpl_toolkits.mplot3d import Axes3D
  import matplotlib.pyplot as plt
  import matplotlib.cm as cm
  
  ra=np.random.random((100))
  dec=np.random.random((100))
  h=np.random.random((100))
  z=np.random.random((100))
  
  datamin=min(h)
  datamax=max(h)
  fig=p.figure()
  
  ax3D=fig.add_subplot(111, projection='3d')
  ax3D.scatter(ra, dec, z, c=h, vmin=datamin, vmax=datamax, 
  marker='o', cmap=cm.Spectral)
  
  p.title("MKW4s-Position vs Velocity")
  p.show()
  </code></pre>