|
| 1 | +# a stacked bar plot with errorbars |
| 2 | +from matplotlib.matlab import * |
| 3 | + |
| 4 | +N = 5 |
| 5 | +menMeans = (20, 35, 30, 35, 27) |
| 6 | +womenMeans = (25, 32, 34, 20, 25) |
| 7 | +menStd = (2, 3, 4, 1, 2) |
| 8 | +womenStd = (3, 5, 2, 3, 3) |
| 9 | +ind = arange(N) # the x locations for the groups |
| 10 | +width = 0.35 # the width of the bars: can also be len(x) sequence |
| 11 | + |
| 12 | +p1 = bar(ind, menMeans, width, color='r', yerr=womenStd) |
| 13 | +p2 = bar(ind, womenMeans, width, color='y', |
| 14 | + bottom=menMeans, yerr=menStd) |
| 15 | + |
| 16 | +ylabel('Scores') |
| 17 | +title('Scores by group and gender') |
| 18 | +set(gca(), 'xticks', ind+(width/2)) |
| 19 | +set(gca(), 'xticklabels', ('G1', 'G2', 'G3', 'G4', 'G5') ) |
| 20 | +set(gca(), 'xlim', [-width,len(ind)]) |
| 21 | +set(gca(), 'yticks', arange(0,81,10)) |
| 22 | +legend( (p1[0], p2[0]), ('Men', 'Women') ) |
| 23 | + |
| 24 | +show() |
0 commit comments