|
7 | 7 | np.random.seed(123) |
8 | 8 | all_data = [np.random.normal(0, std, 100) for std in range(1, 4)] |
9 | 9 |
|
10 | | -fig, axes = plt.subplots(nrows=1,ncols=2, figsize=(12,5)) |
| 10 | +fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12, 5)) |
11 | 11 |
|
12 | 12 | # rectangular box plot |
13 | | -bplot1 = axes[0].boxplot(all_data, |
14 | | - vert=True, # vertical box aligmnent |
15 | | - patch_artist=True) # fill with color |
16 | | - |
| 13 | +bplot1 = axes[0].boxplot(all_data, |
| 14 | + vert=True, # vertical box aligmnent |
| 15 | + patch_artist=True) # fill with color |
| 16 | + |
17 | 17 | # notch shape box plot |
18 | | -bplot2 = axes[1].boxplot(all_data, |
19 | | - notch=True, # notch shape |
20 | | - vert=True, # vertical box aligmnent |
21 | | - patch_artist=True) # fill with color |
| 18 | +bplot2 = axes[1].boxplot(all_data, |
| 19 | + notch=True, # notch shape |
| 20 | + vert=True, # vertical box aligmnent |
| 21 | + patch_artist=True) # fill with color |
22 | 22 |
|
23 | 23 | # fill with colors |
24 | 24 | colors = ['pink', 'lightblue', 'lightgreen'] |
25 | 25 | for bplot in (bplot1, bplot2): |
26 | 26 | for patch, color in zip(bplot['boxes'], colors): |
27 | 27 | patch.set_facecolor(color) |
28 | 28 |
|
29 | | -# adding horizontal grid lines |
| 29 | +# adding horizontal grid lines |
30 | 30 | for ax in axes: |
31 | | - ax.yaxis.grid(True) |
| 31 | + ax.yaxis.grid(True) |
32 | 32 | ax.set_xticks([y+1 for y in range(len(all_data))], ) |
33 | 33 | ax.set_xlabel('xlabel') |
34 | 34 | ax.set_ylabel('ylabel') |
35 | | - |
| 35 | + |
36 | 36 | # add x-tick labels |
37 | | -plt.setp(axes, xticks=[y+1 for y in range(len(all_data))], |
38 | | - xticklabels=['x1', 'x2', 'x3', 'x4'], |
39 | | - ) |
| 37 | +plt.setp(axes, xticks=[y+1 for y in range(len(all_data))], |
| 38 | + xticklabels=['x1', 'x2', 'x3', 'x4']) |
40 | 39 |
|
41 | 40 | plt.show() |
42 | | - |
43 | | - |
0 commit comments