Having a question on showing actual values on the chart. I do have a printed chart and need to show values of each stacked bar. How can I show these values?
I have tried ax.text
function but it does not give desired result(see in picture). As the chart is normalized to 1 I need to show actual values of each stacked bar (at the top is the total number and it should be split to each bar-first bar should have 1 number 7, second bar should have 3 numbers where number 41 is split by the size of each color bar). Is it possible to do this?
My code how I come up with multiple stacked bars:
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
ha='center', va='bottom')
p = [] # list of bar properties
def create_subplot(matrix, colors, axis):
bar_renderers = []
ind = np.arange(matrix.shape[1])
bottoms = np.cumsum(np.vstack((np.zeros(matrix.shape[1]), matrix)), axis=0)[:-1]
for i, row in enumerate(matrix):
print bottoms[i]
r = axis.bar(ind, row, width=0.5, color=colors[i], bottom=bottoms[i])
bar_renderers.append(r)
autolabel(r)
#axis.set_title(title,fontsize=28)
return bar_renderers
p.extend(create_subplot(nauja_matrica,spalvos, ax))