]> git.friedersdorff.com Git - max/plotting_with_matplotlib.git/blobdiff - stacked_bars.py
feat: Stacked bars, pull out time series, saving
[max/plotting_with_matplotlib.git] / stacked_bars.py
diff --git a/stacked_bars.py b/stacked_bars.py
new file mode 100644 (file)
index 0000000..afb9f62
--- /dev/null
@@ -0,0 +1,30 @@
+import numpy as np
+import matplotlib.pyplot as plt
+
+N = 5
+ind = np.arange(N)    # the x locations for the groups
+width = 0.35       # the width of the bars
+
+# Shenanigans because I'm using generated data
+cumulative = np.zeros(N)
+legends = ()
+
+for i in range(0,10):
+    sigma = np.random.rand()*10 + 10
+    mu = np.random.rand()*10 + 50 
+    means = np.abs(sigma*np.random.randn(N) + mu)
+    Stds = np.abs(np.random.rand(N)*2 + 2)
+
+    p = plt.bar(ind, means, width, yerr=Stds, 
+                bottom=cumulative) 
+    cumulative = cumulative + means
+    legends = legends + (p[0],)
+
+plt.ylabel('Scores')
+plt.title('Scores by group and treatment')
+plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
+plt.yticks(np.arange(0, max(cumulative), 30))
+
+plt.legend(legends, range(1, len(legends) + 1))
+
+plt.show()