@@ -134,7 +134,8 @@ def bode_plot(
134
134
If True, draw gain and phase margin lines on the magnitude and phase
135
135
graphs and display the margins at the top of the graph. If set to
136
136
'overlay', the values for the gain and phase margin are placed on
137
- the graph. Setting display_margins turns off the axes grid.
137
+ the graph. Setting `display_margins` turns off the axes grid, unless
138
+ `grid` is explicitly set to True.
138
139
**kwargs : `matplotlib.pyplot.plot` keyword properties, optional
139
140
Additional keywords passed to `matplotlib` to specify line properties.
140
141
@@ -276,6 +277,24 @@ def bode_plot(
276
277
# Make a copy of the kwargs dictionary since we will modify it
277
278
kwargs = dict (kwargs )
278
279
280
+ # Legacy keywords for margins
281
+ display_margins = config ._process_legacy_keyword (
282
+ kwargs , 'margins' , 'display_margins' , display_margins )
283
+ if kwargs .pop ('margin_info' , False ):
284
+ warnings .warn (
285
+ "keyword 'margin_info' is deprecated; "
286
+ "use 'display_margins='overlay'" )
287
+ if display_margins is False :
288
+ raise ValueError (
289
+ "conflicting_keywords: `display_margins` and `margin_info`" )
290
+
291
+ # Turn off grid if display margins, unless explicitly overridden
292
+ if display_margins and 'grid' not in kwargs :
293
+ kwargs ['grid' ] = False
294
+
295
+ margins_method = config ._process_legacy_keyword (
296
+ kwargs , 'method' , 'margins_method' , margins_method )
297
+
279
298
# Get values for params (and pop from list to allow keyword use in plot)
280
299
dB = config ._get_param (
281
300
'freqplot' , 'dB' , kwargs , _freqplot_defaults , pop = True )
@@ -316,19 +335,6 @@ def bode_plot(
316
335
"sharex cannot be present with share_frequency" )
317
336
kwargs ['share_frequency' ] = sharex
318
337
319
- # Legacy keywords for margins
320
- display_margins = config ._process_legacy_keyword (
321
- kwargs , 'margins' , 'display_margins' , display_margins )
322
- if kwargs .pop ('margin_info' , False ):
323
- warnings .warn (
324
- "keyword 'margin_info' is deprecated; "
325
- "use 'display_margins='overlay'" )
326
- if display_margins is False :
327
- raise ValueError (
328
- "conflicting_keywords: `display_margins` and `margin_info`" )
329
- margins_method = config ._process_legacy_keyword (
330
- kwargs , 'method' , 'margins_method' , margins_method )
331
-
332
338
if not isinstance (data , (list , tuple )):
333
339
data = [data ]
334
340
@@ -727,7 +733,7 @@ def _make_line_label(response, output_index, input_index):
727
733
label = '_nyq_mag_' + sysname )
728
734
729
735
# Add a grid to the plot
730
- ax_mag .grid (grid and not display_margins , which = 'both' )
736
+ ax_mag .grid (grid , which = 'both' )
731
737
732
738
# Phase
733
739
if plot_phase :
@@ -742,7 +748,7 @@ def _make_line_label(response, output_index, input_index):
742
748
label = '_nyq_phase_' + sysname )
743
749
744
750
# Add a grid to the plot
745
- ax_phase .grid (grid and not display_margins , which = 'both' )
751
+ ax_phase .grid (grid , which = 'both' )
746
752
747
753
#
748
754
# Display gain and phase margins (SISO only)
@@ -753,6 +759,10 @@ def _make_line_label(response, output_index, input_index):
753
759
raise NotImplementedError (
754
760
"margins are not available for MIMO systems" )
755
761
762
+ if display_margins == 'overlay' and len (data ) > 1 :
763
+ raise NotImplementedError (
764
+ f"{ display_margins = } not supported for multi-trace plots" )
765
+
756
766
# Compute stability margins for the system
757
767
margins = stability_margins (response , method = margins_method )
758
768
gm , pm , Wcg , Wcp = (margins [i ] for i in [0 , 1 , 3 , 4 ])
@@ -844,12 +854,12 @@ def _make_line_label(response, output_index, input_index):
844
854
845
855
else :
846
856
# Put the title underneath the suptitle (one line per system)
847
- ax = ax_mag if ax_mag else ax_phase
848
- axes_title = ax .get_title ()
857
+ ax_ = ax_mag if ax_mag else ax_phase
858
+ axes_title = ax_ .get_title ()
849
859
if axes_title is not None and axes_title != "" :
850
860
axes_title += "\n "
851
861
with plt .rc_context (rcParams ):
852
- ax .set_title (
862
+ ax_ .set_title (
853
863
axes_title + f"{ sysname } : "
854
864
"Gm = %.2f %s(at %.2f %s), "
855
865
"Pm = %.2f %s (at %.2f %s)" %
0 commit comments