Check out our entire Matplotlib playlist here. Pylenin has a dedicated Youtube playlist for Matplotlib Tutorial. Plt.scatter(iris.data, iris.data, c=iris.target) # this formatter will label the colorbar with the correct target namesįormatter = plt.FuncFormatter(lambda i, *args: iris.target_names) # The indices of the features that we are plotting Let’s plot the sepal length vs sepal width from the famous iris data set. Plotting the Iris dataset from Scikit Learn Plt.scatter(x, y, s, c="g", alpha=0.5, marker=r'$\dagger$',Ĭheck out the marker documentation of matplotlib to learn more about markers. # Fixing random state for reproducibility We will use the marker parameter to pass in necessary symbol for our plot. There are four main features of the markers used in a scatter plot that you can customize with plt.scatter(): Size Color Shape Transparency In this section of the tutorial, you’ll learn how to modify all these properties. Let’s plot a scatter plot using the dagger symbol. You can visualize more than two variables on a two-dimensional scatter plot by customizing the markers. You can use any symbol that fits the requirement of your graph. Scatter symbols don’t have to be circular. The above code should produce the following plot. The Matplotlib module has a number of available colormaps.Ī colormap in Matplotlib is like a list of colors, where each color has a value that ranges from 0 to 100. For this purpose, you can use a colormap. When you run this, it produces the following result.īased on the above image, it would be nice to know what each color represents. import matplotlib.pyplot as pltĪs you can see we are passing np.random.rand(N) array as our colours parameter. We can also pass in a sequence of n numbers to be mapped to colors. The above code should produce a similar graph. # You can also mention Hex codes of colors Plt.scatter(x, y1, label='Sin curve', c='green') We can set our own colour for each scatter plot by using the c or the color parameter. Let’s plot both sin and cos curves using scatter plot in the same plot. Let’s plot a simple sin curve using scatter plot.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |