19
19
# Uncomment the following lines to use the qt5 backend instead.
20
20
#
21
21
# import matplotlib
22
- # matplotlib.use('qt5Agg')
22
+ # matplotlib.use('qt5agg')
23
+ #
24
+ # Alternatively, with Python 3.4+ you may add the line
25
+ #
26
+ # import multiprocessing as mp; mp.set_start_method("forkserver")
27
+ #
28
+ # immediately after the ``if __name__ == "__main__"`` check.
23
29
24
30
import matplotlib .pyplot as plt
25
31
@@ -43,30 +49,26 @@ def __init__(self):
43
49
def terminate (self ):
44
50
plt .close ('all' )
45
51
46
- def poll_draw (self ):
47
-
48
- def call_back ():
49
- while self .pipe .poll ():
50
- command = self .pipe .recv ()
51
- if command is None :
52
- self .terminate ()
53
- return False
54
- else :
55
- self .x .append (command [0 ])
56
- self .y .append (command [1 ])
57
- self .ax .plot (self .x , self .y , 'ro' )
58
- self .fig .canvas .draw ()
59
- return True
60
-
61
- return call_back
52
+ def call_back (self ):
53
+ while self .pipe .poll ():
54
+ command = self .pipe .recv ()
55
+ if command is None :
56
+ self .terminate ()
57
+ return False
58
+ else :
59
+ self .x .append (command [0 ])
60
+ self .y .append (command [1 ])
61
+ self .ax .plot (self .x , self .y , 'ro' )
62
+ self .fig .canvas .draw ()
63
+ return True
62
64
63
65
def __call__ (self , pipe ):
64
66
print ('starting plotter...' )
65
67
66
68
self .pipe = pipe
67
69
self .fig , self .ax = plt .subplots ()
68
70
timer = self .fig .canvas .new_timer (interval = 1000 )
69
- timer .add_callback (self .poll_draw () )
71
+ timer .add_callback (self .call_back )
70
72
timer .start ()
71
73
72
74
print ('...done' )
0 commit comments