Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e24476e

Browse files
committed
unpacked and named y, yerr, and axs (previously iterables) for clarity.
1 parent f924d4d commit e24476e

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

examples/lines_bars_and_markers/errorbar_subsample.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,29 @@
1212

1313
# example data
1414
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)
1617

1718
# 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)
1921

2022

2123
# 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))
2626

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)
2830

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)
3334

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))
3838

3939
fig.suptitle('Errorbar subsampling for better appearance')
40-
4140
plt.show()

0 commit comments

Comments
 (0)