I am trying to plot a certain function Q(theta, phi) in spherical coordinate using python's matplotlib package. I want the color to show up as a function of distance to the origin instead of the z coordinate. Is there a way to do this? Here is the code I use to produce the 3D surface plot:
%matplotlib notebook
fig = plt.figure(figsize=(12,12))
ax = fig.add_subplot(111, projection='3d')
X, Y = Q*np.sin(Theta)*np.cos(Phi), Q*np.sin(Theta)*np.sin(Phi)
Z = Q*np.cos(Theta)
ax.plot_surface(X, Y, Z, cmap=plt.cm.YlGnBu_r)
ax.set_zlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_xlim(-1, 1)
ax.set_xlabel('J_x')
ax.set_ylabel('J_y')
ax.set_zlabel('J_z')
plt.show()
I have not earned enough reputations to post the plot I created. It is similar to the plot in this link: https://matplotlib.org/3.1.1/gallery/mplot3d/surface3d.html. As you can see, the color is a function of the z coordinate, not of the distance from the origin.
