
CHANGE COLOR IN SCATTER PLOT PYTHON CODE
The above code means that we are setting the color of the scatter plot as red.

A: You can set the c parameter in the plt.scatter() function to your third. E.g.: import matplotlib.pyplot ( 1,2,3, 4,5,6,color 'red','green','blue') When you have a list of lists and you want them colored per list. Q: How do I change the color of scatter plot markers based on a third variable.

To set the colors of a scatter plot, we need to set the argument color or simply c to the pyplot.scatter() function.įor example, take a look at the code below: plt.scatter(x, y, color = 'red') The normal way to plot plots with points in different colors in matplotlib is to pass a list of colors as a parameter. Those values are then mapped according to the colormap in use. So you can provide a list of numeric values to the scatter via tarray(colorsi), where colorsi 0,1,0.,1,0,1. Setting colors to the multiple scatter plot It can have a colormap associated to it such that its points are colored according to the color array. By default, pyplot returned orange and blue. Note: Notice that the two plots in the figure above gave two different colors. Line 16: The pyplot.show() function is used, which tells pyplot to display both the scatter plots. pyplot.scatter(x,y2) is used to create a scatter plot of x and y2. Lines 12 to 13: The array y2 is created, which contains the y-coordinates for the second scatter plot. pyplot.scatter(x,y1) is used to create a scatter plot of x and y1. Lines 8 to 9: The array y1 is created, which contains the y-coordinates for the first scatter plot. Line 5: The array x is created, containing the x-coordinates common to both plots. Line 2: The numpy module is imported, which will be used to create arrays. Line 1: In matplotlib, the pyplot module is imported, which will be used to create plots.
