Book Image

matplotlib Plotting Cookbook

By : Alexandre Devert
Book Image

matplotlib Plotting Cookbook

By: Alexandre Devert

Overview of this book

Table of Contents (15 chapters)
matplotlib Plotting Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 following script, we display two sets of points, A and B, drawn from two bivariate Gaussian distributions. Each set has its own color. We call pyplot.scatter() twice, once for each point set, as shown in the following script:

import numpy as np
import...