Skip to content

Commit 399fc47

Browse files
committed
MNT: final tweaks
1 parent c8db3e7 commit 399fc47

File tree

11 files changed

+32
-28
lines changed

11 files changed

+32
-28
lines changed

00-explore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
3-
plt.ion()
43

54
last_ev = None
65

@@ -23,6 +22,7 @@ def event_printer(event):
2322
ax.plot(th, np.sin(th), 'o-', picker=5)
2423

2524
cid = fig.canvas.mpl_connect('button_press_event', event_printer)
25+
plt.show()
2626
# fig.canvas.mpl_disconnect(cid)
2727

2828

01-callable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def __call__(self, event):
4040

4141

4242
# EXERCISE
43-
# - Try connecting the same object to events calls
43+
# - Try connecting the same object to other events
4444
# - add helper function to manage event buffer

02-event_filter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import matplotlib.pyplot as plt
22
from itertools import cycle
3-
plt.ion()
4-
53

64
class LineMaker:
75
def __init__(self, ln):
@@ -55,7 +53,7 @@ def on_key(self, event):
5553
fig, ax = plt.subplots()
5654
ln, = ax.plot([], [], '-o')
5755
line_maker = LineMaker(ln)
58-
56+
plt.show()
5957
# EXERCISE
6058
# - modify to remove the closest point when key == 'shift'
6159
# - change the line width for [1-9]

04-spline_demo.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _get_spline(cls, points, pix_err=2, need_sort=True, **kwargs):
129129
pt_lst = list(points)
130130

131131
# compute center
132-
def tmp_fun(x, y): (x[0] + y[0], x[1] + y[1])
132+
tmp_fun = lambda x, y: (x[0] + y[0], x[1] + y[1])
133133

134134
center = np.array(reduce(tmp_fun, pt_lst)).reshape(2, 1)
135135
center /= len(pt_lst)
@@ -269,6 +269,10 @@ def q_phi_to_xy(self, q, phi, cross=None):
269269

270270

271271
fig, ax = plt.subplots()
272+
ax.set_title('left-click to add points, right-click to remove')
272273
sp = SplineFitter(ax, .001)
273-
plt.ion()
274274
plt.show()
275+
276+
277+
# exercise
278+
# - add pick event to move a point

key/00-explore.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
3-
plt.ion()
3+
44

55
last_ev = None
66

@@ -13,7 +13,7 @@ def event_printer(event):
1313
# capture the last event
1414
global last_ev
1515
last_ev = event
16-
if event.inaxes is not None:
16+
if hasattr(event, 'inaxes') and event.inaxes is not None:
1717
print(f'{event.name} ({event.xdata:.3f}, {event.ydata:.3f})')
1818
else:
1919
print(f'{event.name}')
@@ -28,3 +28,6 @@ def event_printer(event):
2828
'scroll_event',
2929
'key_press_event', 'key_release_event',
3030
'pick_event')}
31+
32+
33+
plt.show()

key/02-event_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import matplotlib.pyplot as plt
22
from itertools import cycle
33
import numpy as np
4-
plt.ion()
54

65

76
class LineMaker:
@@ -85,3 +84,4 @@ def on_key(self, event):
8584
fig, ax = plt.subplots()
8685
ln, = ax.plot([], [], '-o')
8786
line_maker = LineMaker(ln)
87+
plt.show()

notes.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ https://www.packtpub.com/application-development/interactive-applications-using-
2828

2929
** install
3030

31-
$ conda create mpl_tut -c anaconda matplotlib pandas pytables ipython python=3.6
31+
$ conda create mpl_tut -c anaconda matplotlib pandas pytables ipython h5py python=3.6
3232
$ source activate mpl_tut
3333

3434
* 00-explore

slides/slides.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,4 @@ new backend).
184184
* 00 Installation
185185
** installation
186186

187-
=conda create mpl_tut -c anaconda matplotlib pandas pytables ipython python=3.6=
187+
=conda create mpl_tut -c anaconda matplotlib pandas pytables h5py ipython python=3.6=

spectral/spectral.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import h5py
77

8+
89
def plot_all_chan_spectrum(spectrum, bins, *, ax=None, **kwargs):
910

1011
def integrate_to_angles(spectrum, bins, lo, hi):
@@ -72,5 +73,5 @@ def update(lo, hi):
7273
spectrum = fin['spectrum'][:]
7374
bins = fin['bins'][:]
7475

75-
plot_all_chan_spectrum(spectrum, bins)
76+
ret = plot_all_chan_spectrum(spectrum, bins)
7677
plt.show()

03-picking.py renamed to weather/03-picking.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import matplotlib.pyplot as plt
2-
from pddc_helpers import (load_bwi_data, aggregate_by_day, extract_day_of_hourly,
3-
label_date)
2+
from w_helpers import load_ornl_data, aggregate_by_day, extract_day_of_hourly
3+
44
import uuid
5-
plt.ion()
65

7-
bwi = load_bwi_data()
8-
bwi = bwi[bwi['year'] > 2014]
9-
bwi_daily = aggregate_by_day(bwi)
6+
7+
ornl = load_ornl_data()
8+
ornl = ornl[ornl['year'] >= 2016]
9+
ornl_daily = aggregate_by_day(ornl)
1010

1111

1212
class RowPrinter:
@@ -39,13 +39,14 @@ def remove(self):
3939

4040

4141
fig, ax = plt.subplots()
42-
ln, = ax.plot('mean', '-o', data=bwi_daily)
42+
ln, = ax.plot('mean', '-o', data=ornl_daily)
4343
ax.set_xlabel('Date [UTC]')
4444
ax.set_ylabel('Air Temperature [℃]')
45-
ax.set_title('BWI')
46-
rp = RowPrinter(ln, bwi_daily)
45+
ax.set_title('ORNL')
46+
rp = RowPrinter(ln, ornl_daily)
4747

48-
one_day = extract_day_of_hourly(bwi, 2015, 10, 18)
48+
one_day = extract_day_of_hourly(ornl, 2015, 10, 18)
49+
plt.show()
4950

5051
# EXERCISE
5152
# - make the print out nicer looking

0 commit comments

Comments
 (0)