@@ -145,19 +145,25 @@ def initPlot(self):
145145 if self .input_ref is None :
146146 self .figure .clear ()
147147 self .ax = self .figure .add_subplot (1 ,1 ,1 )
148- plot_refs = self .ax .plot ([], [])
148+ color_in = 'tab:blue'
149+ plot_refs = self .ax .plot ([], [], color = color_in )
149150 self .input_ref = plot_refs [0 ]
150151
151- plot_refs = self .ax .plot ([], [])
152- self .output_ref = plot_refs [0 ]
153152 self .ax .autoscale (False )
154153
155154 self .ax .set_title ("Click and drag to select data range" )
156155 self .ax .set_xlabel ("Time (s)" )
157- self .ax .set_ylabel ("Amplitude" )
158- self .ax .legend (["Input" , "Output" ])
156+ self .ax .set_ylabel ("Input" , color = color_in )
157+ self .ax .tick_params (axis = 'y' , labelcolor = color_in )
158+
159+ color_out = 'tab:orange'
160+ self .ax_out = self .ax .twinx ()
161+ plot_refs = self .ax_out .plot ([], [], color = color_out )
162+ self .output_ref = plot_refs [0 ]
163+ self .ax_out .set_ylabel ("Output" , color = color_out )
164+ self .ax_out .tick_params (axis = 'y' , labelcolor = color_out )
159165
160- self .span = SpanSelector (self .ax , self .onselect , 'horizontal' , useblit = False ,
166+ self .span = SpanSelector (self .ax_out , self .onselect , 'horizontal' , useblit = False ,
161167 props = dict (alpha = 0.2 , facecolor = 'green' ), interactive = True )
162168
163169 self .canvas .mpl_connect ('scroll_event' , self .zoom_fun )
@@ -166,24 +172,16 @@ def initPlot(self):
166172 def plotU (self ):
167173 self .input_ref .set_xdata (self .t )
168174 self .input_ref .set_ydata (self .u )
169- self .resetXYLim ()
175+ self .ax .set_xlim ([self .t [0 ], self .t [- 1 ]])
176+ self .ax .set_ylim ([min (self .u ), max (self .u )])
170177 self .canvas .draw ()
171178
172179 def plotY (self ):
173180 self .output_ref .set_xdata (self .t )
174181 self .output_ref .set_ydata (self .y )
175- self .resetXYLim ()
176- self .canvas .draw ()
177-
178- def resetXYLim (self ):
179182 self .ax .set_xlim ([self .t [0 ], self .t [- 1 ]])
180-
181- if len (self .u ) > 0 and len (self .y ) > 0 :
182- self .ax .set_ylim ([min ([min (self .u ), min (self .y )]), max ([max (self .u ), max (self .y )])])
183- elif len (self .u ) > 0 :
184- self .ax .set_ylim ([min (self .u ), max (self .u )])
185- elif len (self .y ) > 0 :
186- self .ax .set_ylim ([min (self .y ), max (self .y )])
183+ self .ax_out .set_ylim ([min (self .y ), max (self .y )])
184+ self .canvas .draw ()
187185
188186 def onselect (self , xmin , xmax ):
189187 indmin , indmax = np .searchsorted (self .t , (xmin , xmax ))
0 commit comments