I need some help making a set of stacked bar charts in python with matlibplot. My basic code is below but my problems is how to generate the value for bottom fo
Converting your values to numpy arrays will make your life easier:
data = np.array([a, b, c, d])
bottom = np.cumsum(data, axis=0)
colors = ('#ff3333', '#33ff33', '#3333ff', '#33ffff')
plt.bar(ind, data[0], color=colors[0])
for j in xrange(1, data.shape[0]):
plt.bar(ind, data[1], color=colors[j], bottom=bottom[i-1])
Alternatively, to get rid of the nasty particular case for the first bar:
data = np.array([a, b, c, d])
bottom = np.vstack((np.zeros((data.shape[1],), dtype=data.dtype),
np.cumsum(data, axis=0)[:-1]))
colors = ('#ff3333', '#33ff33', '#3333ff', '#33ffff')
for dat, col, bot in zip(data, colors, bottom):
plt.bar(ind, dat, color=col, bottom=bot)