1"""
2=============================================================
3Demo of the histogram (hist) function with multiple data sets
4=============================================================
5
6Plot histogram with multiple sample sets and demonstrate:
7
8    * Use of legend with multiple sample sets
9    * Stacked bars
10    * Step curve with no fill
11    * Data sets of different sample sizes
12
13Selecting different bin counts and sizes can significantly affect the
14shape of a histogram. The Astropy docs have a great section on how to
15select these parameters:
16http://docs.astropy.org/en/stable/visualization/histogram.html
17"""
18
19import numpy as np
20import matplotlib.pyplot as plt
21
22np.random.seed(19680801)
23
24n_bins = 10
25x = np.random.randn(1000, 3)
26
27fig, axes = plt.subplots(nrows=2, ncols=2)
28ax0, ax1, ax2, ax3 = axes.flatten()
29
30colors = ['red', 'tan', 'lime']
31ax0.hist(x, n_bins, density=True, histtype='bar', color=colors, label=colors)
32ax0.legend(prop={'size': 10})
33ax0.set_title('bars with legend')
34
35ax1.hist(x, n_bins, density=True, histtype='bar', stacked=True)
36ax1.set_title('stacked bar')
37
38ax2.hist(x, n_bins, histtype='step', stacked=True, fill=False)
39ax2.set_title('stack step (unfilled)')
40
41# Make a multiple-histogram of data-sets with different length.
42x_multi = [np.random.randn(n) for n in [10000, 5000, 2000]]
43ax3.hist(x_multi, n_bins, histtype='bar')
44ax3.set_title('different sample sizes')
45
46fig.tight_layout()
47plt.show()
48