I'm trying to display a graph that includes my data using Stacked Bar Charts. My data is;
new_total = [[5,3,11,17,2,1,5,38,30,45,15,0],[8,21,13,54,21,7,20,103,114,149,77,15],[0,2,6,7,2,6,2,6,22,0,3,0],[0,9,3,11,10,0,0,26,47,17,7,9],[0,11,4,2,5,1,10,35,35,19,16,0],[0,0,0,2,0,0,2,5,6,16,4,3]]
It has 6 elements and every elements represents a color (and every element has 12 subelements). To explain with my codes and pictures;
width = 0.5
ind = np.arange(N) # the x locations for the groups
temp = []
myMax = 0
myCount = 0
for x in range(len(movies)):
myCount = myCount + 1
if myCount == 1:
self.axes.bar(ind, new_total[0], width)
temp = np.zeros(N)
else:
if x == len(movies) - 1:
myMax = max(np.add(temp, new_total[x - 1]))
self.axes.bar(ind, new_total[x], width, bottom=np.add(temp, new_total[x - 1]))
If I'm using this code above; this graph is displayed. As you see for example; purple area is in blue area on somewhere. And total numbers (as you see on left) are wrong.
But if I use this code below;
self.axes.bar(ind, new_total[0], width)
self.axes.bar(ind, new_total[1], width, bottom=np.array(new_total[0]))
self.axes.bar(ind, new_total[2], width, bottom=np.add(new_total[0],new_total[1])) #I could use np.array(new_total[0]) + np.array(new_total[1])
self.axes.bar(ind, new_total[3], width, bottom=np.array(new_total[0]) + np.array(new_total[1]) + np.array(new_total[2]))
self.axes.bar(ind, new_total[4], width, bottom=np.array(new_total[0]) + np.array(new_total[1]) + np.array(new_total[2]) + np.array(new_total[3]))
self.axes.bar(ind, new_total[5], width, bottom=np.array(new_total[0]) + np.array(new_total[1]) + np.array(new_total[2]) + np.array(new_total[3]) + np.array(new_total[4]))
This graph is displayed and thats the graph which I want that shows the colors and total numbers perfectly. But I think this solution is so primitive. Because, sometimes the new_total will have 5 or 7 elements whatever. Can you fix my solution with a perfect way (it can has for loop or whatever)