![]() import matplotlib.pyplot as pltplt.scatter (df.Attack, df.Defense, cdf.c, alpha 0. The above code means that we are setting the color of the scatter plot as red. import numpy as np get centroids add to df define and map colors Then we can pass the fields we used to create the cluster to Matplotlib’s scatter and use the ‘c’ column we created to paint the points in our chart according to their cluster. ![]() 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') To plot a scatter graph, use scatter () function. Setting colors to the multiple scatter plot The following are the steps: Import library matplotlib.pyplot. By default, pyplot returned orange and blue. Earlier we saw a tutorial,how to add colors to data points in a scatter plot made with Matplotlib‘s scatter() function. Note: Notice that the two plots in the figure above gave two different colors. datavizpyrMay 8, 2021Matplotlib, one of the powerful Python graphics library, has many way to add colors to a scatter plot and specify legend. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |