简体   繁体   中英

Different colors for different datapoints for matplotlib

I have my x and y coordinates saved in variable x and y respectively. Below is the plot that I get when I make a scatter plot using x,y coordinates. The code used to make the plot is:

import matplotlib.pyplot as plt
for i in range(len(x)):
    plt.scatter(x[i], y[i])

观察到的情节

My question is that even though no color parameter was provided, plt.scatter automatically assigned different colors to the data points though the official documentation suggests that the default value is "b" as for "blue".

The default seems to be None rather than b (although the detailed description of the parameters tells differently).

From the doc : matplotlib.pyplot.scatter(x, y, s=None, c=None,...

So in your case you can fix it with:

for i in range(len(x)):
    plt.scatter(x[i], y[i], c="b")

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