I have a scatterplot and I want to color it based on another value (naively assigned to np.random.random()
in this case).
Is there a way to use
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
x, y, z = np.random.rand(3, 100)
cmap = sns.cubehelix_palette(as_cmap=True)
f, ax = plt.subplots()
points = ax.scatter(x, y, c=z, s=50, cmap=cmap)
f.colorbar(points)
from matplotlib.cm import ScalarMappable
from matplotlib.colors import Normalize
cmap = {obsv_id:np.random.random() for obsv_id in DF_PCA.index}
sm = ScalarMappable(norm=Normalize(vmin=min(list(cmap.values())), vmax=max(list(cmap.values()))), cmap=sns.cubehelix_palette(as_cmap=True))
# Plot
fig, ax = plt.subplots()
ax.scatter(x=DF_PCA["PC1"], y=DF_PCA["PC2"], color=[sm.to_rgba(cmap[obsv_id]) for obsv_id in DF_PCA.index])
ax.set_title("With Coloring")