Using custom colors for scatter plots
We can control the colors used for a scatter plot just as we do for a curve plot. In this recipe, we are going to see how to use the two ways to control the colors of a scatter plot.
Getting ready
The scatter plot function pyplot.scatter()
offers the following two options to control the colors of dots through its color parameter, or its shortcut c
:
- Common color for all the dots: If the color parameter is a valid matplotlib color definition, then all the dots will appear in that color.
- Individual color for each dot: If the color parameter is a sequence of a valid matplotlib color definition, the ith dot will appear in the ith color. Of course, we have to give the required colors for each dot.
How to do it...
In the ...
Get matplotlib Plotting Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.