0

I am attempting to make a stacked bar plot in python, however the final product seems to be missing bars. I believe the first bar should total around 36, but it doesn't. I'm not sure what I am doing wrong. Here is a simplified version of my code:

import numpy as np
import matplotlib.pyplot as plt

a = [7, 12, 10, 12, 11]
b = [1, 5, 3, 5, 4]
c = [0, 2, 0, 2, 0]
d = [1, 5, 0, 0, 0]
e = [1, 2, 0, 1, 0]
f = [2, 10, 1, 1, 0]
g = [4, 4, 0, 1, 0]
h = [5, 4, 0, 1, 0]
i = [4, 10, 0, 2, 1]
j = [1, 1, 0, 3, 0]
k = [7, 5, 3, 15, 7]
l = [3, 7, 4, 4, 1]

ind = np.arange(5)

x = plt.bar(ind, a, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])))
x = plt.bar(ind, b, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)
x = plt.bar(ind, c, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)
x = plt.bar(ind, d, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)
x = plt.bar(ind, e, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)
x = plt.bar(ind, f, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)
x = plt.bar(ind, g, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)
x = plt.bar(ind, h, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)
x = plt.bar(ind, i, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)
x = plt.bar(ind, j, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)
x = plt.bar(ind, k, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)
x = plt.bar(ind, l, color=(np.random.random([1.0]),np.random.random([1.0]),np.random.random([1.0])), bottom=a)

plt.show()

output

user3266890
  • 465
  • 5
  • 15
  • because all of the bars are based on the value in `a`, you need to accumulate. – tacaswell Aug 04 '14 at 23:23
  • See: https://gist.github.com/tacaswell/b1a35a27a7d73f7408d2 – tacaswell Aug 04 '14 at 23:24
  • https://stackoverflow.com/questions/24553474/python-generalized-pyplot-stacked-bars/24554943#24554943 <- related, but hesitant to mark as duplicate as that question is rather hard to understand. – tacaswell Aug 04 '14 at 23:25
  • This is also related, I suppose http://stackoverflow.com/questions/24852852/matplotlib-stacked-bar-graphs/24853866#24853866 – MaxNoe Aug 05 '14 at 08:20
  • @MaxNoe That is a better duplicate, but I have issues with your answer, I left a message over there too. – tacaswell Aug 05 '14 at 13:43

0 Answers0