Using colormaps for bar charts

The pyplot.scatter() function has a built-in support for colormaps; some other plotting functions that we will discover later also have such support. However, some functions, such as pyplot.bar(), do not take colormaps as inputs to plot bar charts. In this recipe, we are going to see how to color a bar chart with a colormap.

matplotlib has helper functions to explicitly generate colors from a colormap. For instance, we can color the bars of a bar chart with the functions of the values they represent.

How to do it...

We will use the matplotlib.cm module in this recipe just as we did in the previous recipe. This time, we will directly use a colormap object rather than letting a rendering function use it automatically. ...

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.