]> git.friedersdorff.com Git - max/plotting_with_matplotlib.git/blob - stacked_bars.py
feat: Add final content
[max/plotting_with_matplotlib.git] / stacked_bars.py
1 import numpy as np
2 import matplotlib.pyplot as plt
3
4 N = 5
5 ind = np.arange(N)    # the x locations for the groups
6 width = 0.35       # the width of the bars
7
8 # Shenanigans because I'm using generated data
9 cumulative = np.zeros(N)
10 legends = ()
11
12 for i in range(0,10):
13     sigma = np.random.rand()*10 + 10
14     mu = np.random.rand()*10 + 50 
15     means = np.abs(sigma*np.random.randn(N) + mu)
16     Stds = np.abs(np.random.rand(N)*2 + 2)
17
18     p = plt.bar(ind, means, width, yerr=Stds, 
19                 bottom=cumulative) 
20     cumulative = cumulative + means
21     legends = legends + (p[0],)
22
23 plt.ylabel('Scores')
24 plt.title('Scores by group and treatment')
25 plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
26 plt.yticks(np.arange(0, max(cumulative), 30))
27
28 plt.legend(legends, range(1, len(legends) + 1))
29
30 plt.show()