Using colormaps for scatter plots

When using a lot of colors, defining each color one by one is tedious. Moreover, building a good set of colors is a problem in itself. In some cases, colormaps can address those issues. Colormaps define colors with a continuous function of one variable to one value, corresponding to one color. matplotlib provides several common colormaps; most of them are continuous color ramps. In this recipe, we are going to see how to color scatter plots with a colormap.

How to do it...

Colormaps are defined in the matplotib.cm module. This module provides functions to create and use colormaps. It also provides an exhaustive choice of predefined color maps.

The function pyplot.scatter() accepts a list of values for the color

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.