Цикл значений в menMeans
и womenMeans
должен дать вам то, что вы хотите:
import numpy as np
import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
womenMeans = (25, 32, 34, 20, 25)
menStd = (2, 3, 4, 1, 2)
womenStd = (3, 5, 2, 3, 3)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence
fig, ax = plt.subplots(1,1)
p1 = ax.bar(ind, menMeans, width, yerr=menStd)
p2 = ax.bar(ind, womenMeans, width,
bottom=menMeans, yerr=womenStd)
for id, men in enumerate(menMeans):
ax.text(id, men+3, str('{}\%'.format(men)))
ax.text(id, men+womenMeans[id]+3, str('{}\%'.format(womenMeans[id])))
Если вы хотите, чтобы общий процент был нанесен поверх женских баров, а непроцент женщин, вы бы сделали:
for id, men in enumerate(menMeans):
ax.text(id, men+3, str('{}\%'.format(men)))
ax.text(id, men+womenMeans[id]+3, str('{}\%'.format(womenMeans[id]+men)))
