@@ -135,6 +135,20 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
135135 else :
136136 omega = sp .logspace (np .log10 (omega_limits [0 ]), np .log10 (omega_limits [1 ]), endpoint = True )
137137
138+ if Plot :
139+ fig = plt .gcf ()
140+ ax_mag = None
141+ ax_phase = None
142+ for ax in fig .axes :
143+ if ax .get_label () == 'pycontrol-bode-mag' :
144+ ax_mag = ax
145+ elif ax .get_label () == 'pycontrol-bode-phs' :
146+ ax_phase = ax
147+ if ax_mag is None or ax_phase is None :
148+ plt .clf ()
149+ ax_mag = plt .subplot (211 , label = 'pycontrol-bode-mag' )
150+ ax_phase = plt .subplot (212 , label = 'pycontrol-bode-phs' , sharex = ax_mag )
151+
138152 mags , phases , omegas , nyquistfrqs = [], [], [], []
139153 for sys in syslist :
140154 if (sys .inputs > 1 or sys .outputs > 1 ):
@@ -172,7 +186,6 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
172186
173187 if (Plot ):
174188 # Magnitude plot
175- ax_mag = plt .subplot (211 );
176189 if dB :
177190 pltline = ax_mag .semilogx (omega_plot , 20 * np .log10 (mag ), * args , ** kwargs )
178191 else :
@@ -186,7 +199,6 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
186199 ax_mag .set_ylabel ("Magnitude (dB)" if dB else "Magnitude" )
187200
188201 # Phase plot
189- ax_phase = plt .subplot (212 , sharex = ax_mag );
190202 if deg :
191203 phase_plot = phase * 180. / math .pi
192204 else :
@@ -354,27 +366,44 @@ def gangof4_plot(P, C, omega=None):
354366 S = feedback (1 , L );
355367 T = L * S ;
356368
369+ plot_axes = {'t' : None , 's' : None , 'ps' : None , 'cs' : None }
370+ for ax in plt .gcf ().axes :
371+ label = ax .get_label ()
372+ if label .startswith ('pycontrol-gof-' ):
373+ key = label [len ('pycontrol-gof-' ):]
374+ if key not in plot_axes :
375+ raise RuntimeError ("unknown gof axis type '{}'" .format (label ))
376+ plot_axes [key ] = ax
377+
378+ # if any are missing, start from scratch
379+ if any ((ax is None for ax in plot_axes .values ())):
380+ plt .clf ()
381+ plot_axes = {'t' : plt .subplot (221 ,label = 'pycontrol-gof-t' ),
382+ 'ps' : plt .subplot (222 ,label = 'pycontrol-gof-ps' ),
383+ 'cs' : plt .subplot (223 ,label = 'pycontrol-gof-cs' ),
384+ 's' : plt .subplot (224 ,label = 'pycontrol-gof-s' )}
385+
357386 # Plot the four sensitivity functions
358387 #! TODO: Need to add in the mag = 1 lines
359388 mag_tmp , phase_tmp , omega = T .freqresp (omega );
360389 mag = np .squeeze (mag_tmp )
361390 phase = np .squeeze (phase_tmp )
362- plt . subplot ( 221 ); plt .loglog (omega , mag );
391+ plot_axes [ 't' ] .loglog (omega , mag );
363392
364393 mag_tmp , phase_tmp , omega = (P * S ).freqresp (omega );
365394 mag = np .squeeze (mag_tmp )
366395 phase = np .squeeze (phase_tmp )
367- plt . subplot ( 222 ); plt .loglog (omega , mag );
396+ plot_axes [ 'ps' ] .loglog (omega , mag );
368397
369398 mag_tmp , phase_tmp , omega = (C * S ).freqresp (omega );
370399 mag = np .squeeze (mag_tmp )
371400 phase = np .squeeze (phase_tmp )
372- plt . subplot ( 223 ); plt .loglog (omega , mag );
401+ plot_axes [ 'cs' ] .loglog (omega , mag );
373402
374403 mag_tmp , phase_tmp , omega = S .freqresp (omega );
375404 mag = np .squeeze (mag_tmp )
376405 phase = np .squeeze (phase_tmp )
377- plt . subplot ( 224 ); plt .loglog (omega , mag );
406+ plot_axes [ 's' ] .loglog (omega , mag );
378407
379408#
380409# Utility functions
0 commit comments