|
12 | 12 |
|
13 | 13 | # example data
|
14 | 14 | x = np.arange(0.1, 4, 0.1)
|
15 |
| -y = np.exp(np.vstack([-1.0 * x, -.5 * x])) |
| 15 | +y1 = np.exp(-1.0 * x) |
| 16 | +y2 = np.exp(-0.5 * x) |
16 | 17 |
|
17 | 18 | # example variable error bar values
|
18 |
| -yerr = 0.1 + 0.1 * np.sqrt(np.vstack([x, x/2])) |
| 19 | +y1err = 0.1 + 0.1 * np.sqrt(x) |
| 20 | +y2err = 0.1 + 0.1 * np.sqrt(x/2) |
19 | 21 |
|
20 | 22 |
|
21 | 23 | # Now switch to a more OO interface to exercise more features.
|
22 |
| -fig, axs = plt.subplots(nrows=1, ncols=3, sharex=True, figsize=(12, 6)) |
23 |
| -ax = axs[0] |
24 |
| -for i in range(2): |
25 |
| - ax.errorbar(x, y[i], yerr=yerr[i]) |
| 24 | +fig, (ax_l, ax_c, ax_r) = plt.subplots(nrows=1, ncols=3, |
| 25 | + sharex=True, figsize=(12, 6)) |
26 | 26 |
|
27 |
| -ax.set_title('all errorbars') |
| 27 | +ax_l.set_title('all errorbars') |
| 28 | +ax_l.errorbar(x, y1, yerr=y1err) |
| 29 | +ax_l.errorbar(x, y2, yerr=y2err) |
28 | 30 |
|
29 |
| -ax = axs[1] |
30 |
| -for i in range(2): |
31 |
| - ax.errorbar(x, y[i], yerr=yerr[i], errorevery=6) |
32 |
| -ax.set_title('only every 6th errorbar') |
| 31 | +ax_c.set_title('only every 6th errorbar') |
| 32 | +ax_c.errorbar(x, y1, yerr=y1err, errorevery=6) |
| 33 | +ax_c.errorbar(x, y2, yerr=y2err, errorevery=6) |
33 | 34 |
|
34 |
| -ax = axs[2] |
35 |
| -for i in range(2): |
36 |
| - ax.errorbar(x, y[i], yerr=yerr[i], errorevery=(3 * i, 6)) |
37 |
| -ax.set_title('second series shifted by 3') |
| 35 | +ax_r.set_title('second series shifted by 3') |
| 36 | +ax_r.errorbar(x, y1, yerr=y1err, errorevery=(0, 6)) |
| 37 | +ax_r.errorbar(x, y2, yerr=y2err, errorevery=(3, 6)) |
38 | 38 |
|
39 | 39 | fig.suptitle('Errorbar subsampling for better appearance')
|
40 |
| - |
41 | 40 | plt.show()
|
0 commit comments