Srijan Sharma
Srijan Sharma

Reputation: 693

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])

Plot Observed

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".

Upvotes: 1

Views: 429

Answers (1)

petezurich
petezurich

Reputation: 10174

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")

Upvotes: 1

Related Questions