|
1 |
| -# a bar plot with errorbars |
| 1 | +""" |
| 2 | +A bar plot with errorbars and height labels on individual bars |
| 3 | +""" |
2 | 4 | import numpy as np
|
3 | 5 | import matplotlib.pyplot as plt
|
4 | 6 |
|
5 | 7 | N = 5
|
6 |
| -menMeans = (20, 35, 30, 35, 27) |
7 |
| -menStd = (2, 3, 4, 1, 2) |
| 8 | +men_means = (20, 35, 30, 35, 27) |
| 9 | +men_std = (2, 3, 4, 1, 2) |
8 | 10 |
|
9 | 11 | ind = np.arange(N) # the x locations for the groups
|
10 | 12 | width = 0.35 # the width of the bars
|
11 | 13 |
|
12 | 14 | fig, ax = plt.subplots()
|
13 |
| -rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd) |
| 15 | +rects1 = ax.bar(ind, men_means, width, color='r', yerr=men_std) |
14 | 16 |
|
15 |
| -womenMeans = (25, 32, 34, 20, 25) |
16 |
| -womenStd = (3, 5, 2, 3, 3) |
17 |
| -rects2 = ax.bar(ind + width, womenMeans, width, color='y', yerr=womenStd) |
| 17 | +women_means = (25, 32, 34, 20, 25) |
| 18 | +women_std = (3, 5, 2, 3, 3) |
| 19 | +rects2 = ax.bar(ind + width, women_means, width, color='y', yerr=women_std) |
18 | 20 |
|
19 | 21 | # add some text for labels, title and axes ticks
|
20 | 22 | ax.set_ylabel('Scores')
|
|
26 | 28 |
|
27 | 29 |
|
28 | 30 | def autolabel(rects):
|
29 |
| - # attach some text labels |
| 31 | + """ |
| 32 | + Attach a text label above each bar displaying its height |
| 33 | + """ |
30 | 34 | for rect in rects:
|
31 | 35 | height = rect.get_height()
|
32 | 36 | ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
|
|
0 commit comments