8000 Cleanup and move errorbar_demo. · matplotlib/matplotlib@7f1887b · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f1887b

Browse files
committed
Cleanup and move errorbar_demo.
Split demo in to two different examples
1 parent 48caac8 commit 7f1887b

File tree

3 files changed

+52
-48
lines changed

3 files changed

+52
-48
lines changed

examples/pylab_examples/errorbar_demo.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

examples/statistics/errorbar_demo.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Demo of the errorbar function.
3+
"""
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
7+
# example data
8+
x = np.arange(0.1, 4, 0.5)
9+
y = np.exp(-x)
10+
11+
plt.errorbar(x, y, xerr=0.2, yerr=0.4)
12+
plt.show()
13+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Demo of errorbar function with different ways of specifying error bars.
3+
4+
Errors can be specified as a constant value (as shown in `errorbar_demo.py`),
5+
or as demonstrated in this example, they can be specified by an N x 1 or 2 x N,
6+
where N is the number of data points.
7+
8+
N x 1:
9+
Error varies for each point, but the error values are symmetric (i.e. the
10+
lower and upper values are equal).
11+
12+
2 x N:
13+
Error varies for each point, and the lower and upper limits (in that order)
14+
are different (asymmetric case)
15+
16+
In addition, this example demonstrates how to use log scale with errorbar.
17+
"""
18+
import numpy as np
19+
import matplotlib.pyplot as plt
20+
21+
# example data
22+
x = np.arange(0.1, 4, 0.5)
23+
y = np.exp(-x)
24+
# example error bar values that vary with x-position
25+
error = 0.1 + 0.2 * x
26+
# error bar values w/ different -/+ errors
27+
lower_error = 0.4 * error
28+
upper_error = error
29+
asymmetric_error = [lower_error, upper_error]
30+
31+
fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)
32+
ax0.errorbar(x, y, yerr=error, fmt='-o')
33+
ax0.set_title('variable, symmetric error')
34+
35+
ax1.errorbar(x, y, xerr=asymmetric_error, fmt='o')
36+
ax1.set_title('variable, asymmetric error')
37+
ax1.set_yscale('log')
38+
plt.show()
39+

0 commit comments

Comments
 (0)
0