Neal Mc Beal
Neal Mc Beal

Reputation: 245

Python Matplotlib: How to change color of markers?

i read the book "Machine Learning Algorithms" from Packt and there is a code sample which i tried to reproduce. I have some problems with the color of the markers inside this scatter plot.

The code is the following:

from sklearn.datasets import make_circles

nb_samples = 500
X, Y = make_circles(n_samples=nb_samples, noise=0.1)

This produces a circle with data. The picture in the book looks like that: Picture of the book

I tried to reproduce this with:

from sklearn.datasets import make_circles
import matplotlib.pyplot as plt

nb_samples = 500
X, Y = make_circles(n_samples=nb_samples, noise=0.1)
plt.scatter(X[:, 0], X[:, 1])
plt.show()

And the output is the following:

My solution

I want to know how to set a different color and markers for the data points. Maybe my code is wrong and i shouldn't plot X[:, 0], X[:, 1]. I hope someone can help me.

Upvotes: 1

Views: 583

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339052

The color is supposedly produced by the other return value of make_circles. Hence

plt.scatter(X[:, 0], X[:, 1], c=Y, cmap="bwr")

enter image description here

Upvotes: 2

Related Questions