You can specify one color for all the circles, or you can vary the color. The above code means that we are setting the color of the scatter plot as red. scatter( x, y, sz, c ) specifies the circle colors. 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') Setting colors to the multiple scatter plot 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. Python3 import matplotlib. Here we will plot a simple scatterplot with x and y data, Then will use c attributes for coloring the point (Scatterplot variable points). In this example, We are going to see how to color scatterplot with their variable value. Lines 12 to 13: The array y2 is created, which contains the y-coordinates for the second scatter plot. Example 1: Color Scatterplot by variable values. 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. Example 1: Color Scatterplot by variable values.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |