@@ -135,7 +135,8 @@ def bode_plot(
135135 If True, draw gain and phase margin lines on the magnitude and phase
136136 graphs and display the margins at the top of the graph. If set to
137137 'overlay', the values for the gain and phase margin are placed on
138- the graph. Setting display_margins turns off the axes grid.
138+ the graph. Setting `display_margins` turns off the axes grid, unless
139+ `grid` is explicitly set to True.
139140 **kwargs : `matplotlib.pyplot.plot` keyword properties, optional
140141 Additional keywords passed to `matplotlib` to specify line properties.
141142
@@ -277,6 +278,24 @@ def bode_plot(
277278 # Make a copy of the kwargs dictionary since we will modify it
278279 kwargs = dict (kwargs )
279280
281+ # Legacy keywords for margins
282+ display_margins = config ._process_legacy_keyword (
283+ kwargs , 'margins' , 'display_margins' , display_margins )
284+ if kwargs .pop ('margin_info' , False ):
285+ warnings .warn (
286+ "keyword 'margin_info' is deprecated; "
287+ "use 'display_margins='overlay'" )
288+ if display_margins is False :
289+ raise ValueError (
290+ "conflicting_keywords: `display_margins` and `margin_info`" )
291+
292+ # Turn off grid if display margins, unless explicitly overridden
293+ if display_margins and 'grid' not in kwargs :
294+ kwargs ['grid' ] = False
295+
296+ margins_method = config ._process_legacy_keyword (
297+ kwargs , 'method' , 'margins_method' , margins_method )
298+
280299 # Get values for params (and pop from list to allow keyword use in plot)
281300 dB = config ._get_param (
282301 'freqplot' , 'dB' , kwargs , _freqplot_defaults , pop = True )
@@ -317,19 +336,6 @@ def bode_plot(
317336 "sharex cannot be present with share_frequency" )
318337 kwargs ['share_frequency' ] = sharex
319338
320- # Legacy keywords for margins
321- display_margins = config ._process_legacy_keyword (
322- kwargs , 'margins' , 'display_margins' , display_margins )
323- if kwargs .pop ('margin_info' , False ):
324- warnings .warn (
325- "keyword 'margin_info' is deprecated; "
326- "use 'display_margins='overlay'" )
327- if display_margins is False :
328- raise ValueError (
329- "conflicting_keywords: `display_margins` and `margin_info`" )
330- margins_method = config ._process_legacy_keyword (
331- kwargs , 'method' , 'margins_method' , margins_method )
332-
333339 if not isinstance (data , (list , tuple )):
334340 data = [data ]
335341
@@ -728,7 +734,7 @@ def _make_line_label(response, output_index, input_index):
728734 label = '_nyq_mag_' + sysname )
729735
730736 # Add a grid to the plot
731- ax_mag .grid (grid and not display_margins , which = 'both' )
737+ ax_mag .grid (grid , which = 'both' )
732738
733739 # Phase
734740 if plot_phase :
@@ -743,7 +749,7 @@ def _make_line_label(response, output_index, input_index):
743749 label = '_nyq_phase_' + sysname )
744750
745751 # Add a grid to the plot
746- ax_phase .grid (grid and not display_margins , which = 'both' )
752+ ax_phase .grid (grid , which = 'both' )
747753
748754 #
749755 # Display gain and phase margins (SISO only)
@@ -754,6 +760,10 @@ def _make_line_label(response, output_index, input_index):
754760 raise NotImplementedError (
755761 "margins are not available for MIMO systems" )
756762
763+ if display_margins == 'overlay' and len (data ) > 1 :
764+ raise NotImplementedError (
765+ f"{ display_margins = } not supported for multi-trace plots" )
766+
757767 # Compute stability margins for the system
758768 margins = stability_margins (response , method = margins_method )
759769 gm , pm , Wcg , Wcp = (margins [i ] for i in [0 , 1 , 3 , 4 ])
@@ -847,12 +857,12 @@ def _make_line_label(response, output_index, input_index):
847857
848858 else :
849859 # Put the title underneath the suptitle (one line per system)
850- ax = ax_mag if ax_mag else ax_phase
851- axes_title = ax .get_title ()
860+ ax_ = ax_mag if ax_mag else ax_phase
861+ axes_title = ax_ .get_title ()
852862 if axes_title is not None and axes_title != "" :
853863 axes_title += "\n "
854864 with plt .rc_context (rcParams ):
855- ax .set_title (
865+ ax_ .set_title (
856866 axes_title + f"{ sysname } : "
857867 "Gm = %.2f %s(at %.2f %s), "
858868 "Pm = %.2f %s (at %.2f %s)" %
0 commit comments