How to set markers color in Scatter plot in Matplotlib?

If you want to set the color of the markers in the scatter plot, you have to pass colors to the keyword argument c of the scatter() function.

matplotlib.pyplot.scatter(x, y, s=None, c=None)

It is important to note that you can specify colors in hexadecimal RGB string, CSS color names, and other formats. If you want to learn the different ways of setting colors in Matplotlib, then visit Matplotlib colors.

To set the colors of each data point, pass a list having color value for each marker to the keyword argument c. The length of this list must be equal to the number of data points. On the other hand, if you want to set the same color for each data point, then simply pass a color value to the keyword argument c.

In the following example, we will draw a scatter plot having 10 data points. Here, we will set the color of each data point using the hexadecimal RGB string.

import matplotlib.pyplot as plt

#Data Points
x = [1, 1, 3, 2, 2, 3, 4, 5, 4, 7]
y = [4, 3, 2, 4, 7, 4, 1, 10, 3, 2]
#Markers Colors
markersColors = ['#D32F2F', '#C2185B', '#7B1FA2', '#512DA8', '#303F9F', '#1976D2', '#F57C00', '#5D4037', '#616161', '#689F38']

#Draw Scatter Plot
plt.scatter(x, y, c=markersColors)
#Show Scatter Plot
plt.show()

Output

Matplotlib markers color scatter plot

Let's set the color of each marker using CSS color names in the following example.

import matplotlib.pyplot as plt

#Data Points
x = [1, 1, 3, 2, 2, 3, 4, 5, 4, 7]
y = [4, 3, 2, 4, 7, 4, 1, 10, 3, 2]
#Markers Colors
markersColors = ['lime', 'yellow', 'blue', 'gold', 'brown', 'olive', 'orchid', 'cyan', 'slategrey', 'indigo']

#Draw Scatter Plot
plt.scatter(x, y, c=markersColors)
#Show Scatter Plot
plt.show()

Output

Matplotlib markers color scatter plot