@@ -71,25 +71,39 @@ class PyPlotHelper(PlotHelper):
7171 def __init__ (self , channels : dict [int , tuple [str , str ]], max_value_count : int ):
7272 super ().__init__ ()
7373
74+ self ._window_closed = False
7475 x_dimension , y_dimension = self ._calc_layout_dimension (len (channels ))
7576 self ._figure , self ._axes = plt .subplots (y_dimension , x_dimension , constrained_layout = True , squeeze = False )
77+ self ._figure .canvas .mpl_connect ("close_event" , self ._on_close )
7678
7779 for (key , value ), sub_plot in zip (channels .items (), self ._axes .flat ):
7880 sub_plot .set (xlabel = "Samples" , ylabel = value [0 ], title = value [0 ])
7981 self ._data [key ] = PyPlotValueChannel (sub_plot , max_value_count , value [1 ])
8082
8183 # interactive mode and show plot
82- self ._animation_result = animation .FuncAnimation (self ._figure , self ._animation , interval = 100 )
83- # plt.ion()
84+ self ._animation_result = animation .FuncAnimation (self ._figure , self ._animation ,
85+ interval = 100 , save_count = max_value_count )
86+ plt .ion ()
8487 plt .show (block = False )
88+ self .update ()
8589
8690
8791 def update (self ):
8892 """Wait for a short time to process events"""
8993 plt .pause (0.0001 )
9094
9195
96+ def loop (self ):
97+ """Run event loop until plot window closed"""
98+ while not self ._window_closed :
99+ self .update ()
100+
101+
92102 def _animation (self , frame : int , * fargs : tuple ): # pylint:disable=unused-argument
93103 """This function is call in context of main thread"""
94104 for x in self ._data .values ():
95105 x .update_plot ()
106+
107+
108+ def _on_close (self , event ):
109+ self ._window_closed = True
0 commit comments