![]() ![]() The itertools.cycle() method will create a cyclic list of colors from the given set of colors, and each row is plotted in the scatter plot picking a color from the cyclic list. ![]() Plt.scatter(x,row,color=next(color_cycle)) We will learn about the scatter plot from the matplotlib library. import itertoolsĬolor_cycle= itertools.cycle() It is used for plotting various plots in Python like scatter plot, bar charts, pie charts, line plots, histograms, 3-D plots and many more. To iterate over the color, we use the next() function. Instead of using the generated color map, we can also specify colors to be used for scatter plots in a list and pass the list to the itertools.cycle() method to make a custom color cycler. It generates different colors for each row in the matrix y and plots each row with a different color. import numpy as npĬolors = cm.rainbow(np.linspace(0, 1, y.shape)) In such cases, we can use colormap to generate the colors for each set of data. It will be difficult to assign color manually every time to each dataset if there are a huge number of datasets. Here, the dataset y1 is represented in the scatter plot by the red color while the dataset y2 is represented in the scatter plot by the green color. Plt.title("Scatter Plot of two different datasets") If we have two different datasets, we can use different colors for each dataset using the different values of the c parameter. Here, we set the color of all the markers in the scatterplots to red by setting c="red" in the scatter() method. Set the Color of a Marker in the Scatterplot import matplotlib.pyplot as plt To set the color of markers in Matplotlib, we set the c parameter in () method. Matplotlib Matplotlib Scatter Plot Matplotlib Color ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |