1919# Uncomment the following lines to use the qt5 backend instead.
2020#
2121# 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.
2329
2430import matplotlib .pyplot as plt
2531
@@ -43,30 +49,26 @@ def __init__(self):
4349 def terminate (self ):
4450 plt .close ('all' )
4551
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
6264
6365 def __call__ (self , pipe ):
6466 print ('starting plotter...' )
6567
6668 self .pipe = pipe
6769 self .fig , self .ax = plt .subplots ()
6870 timer = self .fig .canvas .new_timer (interval = 1000 )
69- timer .add_callback (self .poll_draw () )
71+ timer .add_callback (self .call_back )
7072 timer .start ()
7173
7274 print ('...done' )
0 commit comments