forked from matplotlib/interactive_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path04-custom_plotting.py
57 lines (48 loc) · 1.77 KB
/
04-custom_plotting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import matplotlib.pyplot as plt
from pddc_helpers import load_bwi_data, aggregate_by_month
plt.ion()
bwi = load_bwi_data()
bwi_monthly = aggregate_by_month(bwi)
fig, ax = plt.subplots()
def plot_aggregated_errorbar(ax, gb, label, picker=None, **kwargs):
kwargs.setdefault('capsize', 3)
kwargs.setdefault('markersize', 5)
kwargs.setdefault('marker', 'o')
eb = ax.errorbar(gb.index, 'mean',
yerr='std',
data=gb,
label=label,
picker=picker,
**kwargs)
fill = ax.fill_between(gb.index, 'min', 'max', alpha=.5,
data=gb, color=eb[0].get_color())
ax.legend()
ax.figure.canvas.draw_idle()
return eb, fill
arts = plot_aggregated_errorbar(ax, bwi_monthly, 'bwi')
# EXERCISE
# - make the shaded area configurable
# - make center line configurable
def plot_aggregated_errorbar(ax, gb, label, picker=None, *,
bands=None,
center_line='mean',
**kwargs):
if bands is None:
bands = ['min', 'max']
kwargs.setdefault('capsize', 3)
kwargs.setdefault('markersize', 5)
kwargs.setdefault('marker', 'o')
eb = ax.errorbar(gb.index, center_line,
yerr='std',
data=gb,
label=label,
picker=picker,
**kwargs)
fill = ax.fill_between(gb.index, *bands, alpha=.5,
data=gb, color=eb[0].get_color())
ax.legend()
ax.figure.canvas.draw_idle()
return eb, fill
arts = plot_aggregated_errorbar(ax, bwi_monthly, 'bwi',
bands=['25%', '75%'],
center_line='50%')