I am trying to use ax.scatter to plot a 3D scatter. I read the data from the fits file and saved the data from the three columns in x, y, z. And I made sure that the data x, y, z have the same size. z was normalized between 0 and 1.
import numpy as np import matplotlib from matplotlib import pylab,mlab,pyplot,cm plt = pyplot import pyfits as pf from mpl_toolkits.mplot3d import Axes3D import fitsio data = fitsio.read("xxx.fits") x=data["x"] y=data["y"] z=data["z"] z = (z-np.nanmin(z)) /(np.nanmax(z) - np.nanmin(z)) Cen3D = plt.figure() ax = Cen3D.add_subplot(111, projection='3d') cmap=cm.ScalarMappable(norm=z, cmap=plt.get_cmap('hot')) ax.scatter(x,y,z,zdir=u'z',cmap=cmap) ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') plt.show()
What I'm trying to achieve is to use color to indicate z size. Like a higher z value, it gets darker. But I keep getting the plot without the color map I want, they are all the same by default in blue. What have I done wrong? Thanks.
source share