Plotting multiple bar charts

When comparing several quantities and when changing one variable, we might want a bar chart where we have bars of one color for one quantity value.

How to do it...

We can plot multiple bar charts by playing with the thickness and the positions of the bars as follows:

import numpy as np
import matplotlib.pyplot as plt

data = [[5., 25., 50., 20.],
  [4., 23., 51., 17.],
  [6., 22., 52., 19.]]

X = np.arange(4)
plt.bar(X + 0.00, data[0], color = 'b', width = 0.25)
plt.bar(X + 0.25, data[1], color = 'g', width = 0.25)
plt.bar(X + 0.50, data[2], color = 'r', width = 0.25)

plt.show()

The preceding script will produce the following graph:

How it works...

The data variable contains three series of four values. The preceding script will ...

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.