简体   繁体   中英

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: 这本书的图片

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:

我的解决方案

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.

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

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM