Natalie
Natalie

Reputation: 11

Color code points on 3D scatter plot with 350 points

I am doing PCA, that has 350 points to plot. I have successfully plotted them on a 3D plot. I want to color them to tell which point is which on my 3D plot. Is it possible to color each one? Maybe color points 1 to 50 different shades of green, then 51 to 100 different shades of red, etc? And the lighter the shade of color the smaller the number is?

Upvotes: 1

Views: 1665

Answers (1)

LABarnard
LABarnard

Reputation: 290

You mentioned you have been trying to do this with matplotlib and ax.scatter. I think for your example all the functionality you need is already built into ax.scater, with the c input argument. For example, does the following meet your requirements?

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

# Some dummy data
xval = np.random.randn(350)
yval = np.random.randn(350)
zval = np.exp( - (xval**2 + yval**2)/0.5)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

cax = ax.scatter(xval, yval, zval, cmap=plt.cm.viridis, c=zval) 
fig.colorbar(cax)

enter image description here

Upvotes: 3

Related Questions