2020# [ ] Add line labels to gangof4
2121# [ ] Update FRD to allow nyquist_response contours
2222# [ ] Allow frequency range to be overridden in bode_plot
23+ # [ ] Unit tests for discrete time systems with different sample times
2324
2425#
2526# This file contains some standard control system plots: Bode plots,
@@ -615,18 +616,15 @@ def _share_axes(ref, share_map, axis):
615616 phase = phase_data [index ].reshape ((noutputs , ninputs , - 1 ))
616617 omega_sys , sysname = response .omega , response .sysname
617618
618- # Keep track of Nyquist frequency for discrete time systems
619- nyq_freq = None if response .isctime () else math .pi / response .dt
620-
621619 for i , j in itertools .product (range (noutputs ), range (ninputs )):
622620 # Get the axes to use for magnitude and phase
623621 ax_mag = ax_array [mag_map [i , j ]]
624622 ax_phase = ax_array [phase_map [i , j ]]
625623
626624 # Get the frequencies and convert to Hz, if needed
627625 omega_plot = omega_sys / (2 * math .pi ) if Hz else omega_sys
628- if nyq_freq is not None and Hz :
629- nyq_freq = nyq_freq / ( 2 * math .pi )
626+ if response . isdtime ( strict = True ) :
627+ nyq_freq = 0.5 / response . dt if Hz else math .pi / response . dt
630628
631629 # Save the magnitude and phase to plot
632630 mag_plot = 20 * np .log10 (mag [i , j ]) if dB else mag [i , j ]
@@ -642,14 +640,13 @@ def _share_axes(ref, share_map, axis):
642640 omega_plot , mag_plot , * fmt , label = sysname , ** kwargs )
643641 out [mag_map [i , j ]] += lines
644642
645- # Plot vertical line at Nyquist frequency
646- # TODO: move this until after all data are plotted
647- if nyq_freq :
648- pltfcn (
649- [nyq_freq , nyq_freq ], ax_mag .get_ylim (),
650- color = lines [0 ].get_color (), linestyle = '--' )
643+ # Save the information needed for the Nyquist line
644+ if response .isdtime (strict = True ):
645+ ax_mag .axvline (
646+ nyq_freq , color = lines [0 ].get_color (), linestyle = '--' ,
647+ label = '_nyq_mag_' + sysname )
651648
652- # Add a grid to the plot + labeling
649+ # Add a grid to the plot + labeling (TODO? move to later?)
653650 ax_mag .grid (grid and not margins , which = 'both' )
654651
655652 # Phase
@@ -658,12 +655,11 @@ def _share_axes(ref, share_map, axis):
658655 omega_plot , phase_plot , * fmt , label = sysname , ** kwargs )
659656 out [phase_map [i , j ]] += lines
660657
661- # Plot vertical line at Nyquist frequency
662- # TODO: move this until after all data are plotted
663- if nyq_freq :
664- ax_phase .semilogx (
665- [nyq_freq , nyq_freq ], ax_phase .get_ylim (),
666- color = lines [0 ].get_color (), linestyle = '--' )
658+ # Save the information needed for the Nyquist line
659+ if response .isdtime (strict = True ):
660+ ax_phase .axvline (
661+ nyq_freq , color = lines [0 ].get_color (), linestyle = '--' ,
662+ label = '_nyq_phase_' + sysname )
667663
668664 # Add a grid to the plot + labeling
669665 ax_phase .grid (grid and not margins , which = 'both' )
@@ -1015,14 +1011,14 @@ def gen_zero_centered_series(val_min, val_max, period):
10151011 for j in range (ncols ):
10161012 ax = ax_array [i , j ]
10171013 # Get the labels to use, removing common strings
1018- labels = _make_legend_labels (
1019- [ line . get_label () for line in ax . get_lines ()
1020- if line .get_label ()[ 0 ] != '_' ])
1014+ lines = [ line for line in ax . get_lines ()
1015+ if line . get_label ()[ 0 ] != '_' ]
1016+ labels = _make_legend_labels ([ line .get_label () for line in lines ])
10211017
10221018 # Generate the label, if needed
10231019 if len (labels ) > 1 and legend_map [i , j ] != None :
10241020 with plt .rc_context (freqplot_rcParams ):
1025- ax .legend (labels , loc = legend_map [i , j ])
1021+ ax .legend (lines , labels , loc = legend_map [i , j ])
10261022
10271023 #
10281024 # Legacy return pocessing
0 commit comments