2

I am trying to represent points in 2d space with according label, I also want the points to have the same color as their label and finally I need the colors of the labels to be progressive.

I looked everywhere but I can't seem to find a solution. This is my current implementation :

for i in range(0, encoder.classes_.size):
       plt.scatter(data_pca_reduced[i][0], data_pca_reduced[i][1],
                   label=i, cmap=plt.get_cmap('viridis'))

And this is the result :

Scatter plot result

As you can see the labels colors are not progressive.

CuriousLearner
  • 121
  • 1
  • 7
  • Hey, have you seen https://stackoverflow.com/questions/40803570/python-matplotlib-scatter-plot-specify-color-points-depending-on-conditions – 404pio Aug 27 '19 at 09:31
  • 2
    Or this one: https://stackoverflow.com/questions/12236566/setting-different-color-for-each-series-in-scatter-plot-on-matplotlib – 404pio Aug 27 '19 at 09:32
  • You need one single scatter only. No loop. And you need a [mcve] in the question, such that people feel motivated to answer. – ImportanceOfBeingErnest Aug 27 '19 at 09:43

1 Answers1

1

Thanks the second link is exactly what I was looking for !

Now this is the working code :

colors = matplotlib.cm.rainbow(np.linspace(0, 1, encoder.classes_.size))
for i, c in zip(range(encoder.classes_.size), colors):
       plt.scatter(data_pca_reduced[i][0], data_pca_reduced[i][1], label=i, color=c)

And this is the result : result image

CuriousLearner
  • 121
  • 1
  • 7