@@ -126,7 +126,7 @@ def test_plot_ax_processing(resp_fcn, plot_fcn):
126126 if resp_fcn is not None :
127127 cplt3 = resp .plot (** kwargs , ** meth_kwargs , ax = cplt1 .axes )
128128 else :
129- cplt3 = plot_fcn (* args , ** kwargs , ** meth_kwargs )
129+ cplt3 = plot_fcn (* args , ** kwargs , ** meth_kwargs , ax = cplt1 . axes )
130130 assert cplt3 .figure == cplt1 .figure
131131
132132 # Plot should have landed on top of previous plot, in different colors
@@ -136,6 +136,51 @@ def test_plot_ax_processing(resp_fcn, plot_fcn):
136136 assert get_line_color (cplt3 ) != get_line_color (cplt1 )
137137 assert get_line_color (cplt3 ) != get_line_color (cplt2 )
138138
139+ #
140+ # Plot on a user-contructed figure
141+ #
142+
143+ # Store modified properties from previous figure
144+ cplt_titlesize = cplt3 .figure ._suptitle .get_fontsize ()
145+ cplt_labelsize = \
146+ cplt3 .axes .reshape (- 1 )[0 ].get_yticklabels ()[0 ].get_fontsize ()
147+
148+ # Set up some axes with a known title
149+ fig , axs = plt .subplots (2 , 3 )
150+ title = "User-constructed figure"
151+ plt .suptitle (title )
152+ titlesize = fig ._suptitle .get_fontsize ()
153+ assert titlesize != cplt_titlesize
154+ labelsize = axs [0 , 0 ].get_yticklabels ()[0 ].get_fontsize ()
155+ assert labelsize != cplt_labelsize
156+
157+ # Figure out what to pass as the ax keyword
158+ match resp_fcn , plot_fcn :
159+ case _, ct .bode_plot :
160+ ax = [axs [0 , 1 ], axs [1 , 1 ]]
161+
162+ case ct .gangof4_response , _:
163+ ax = [axs [0 , 1 ], axs [0 , 2 ], axs [1 , 1 ], axs [1 , 2 ]]
164+
165+ case (ct .forced_response | ct .input_output_response , _):
166+ ax = [axs [0 , 1 ], axs [1 , 1 ]]
167+
168+ case _, _:
169+ ax = [axs [0 , 1 ]]
170+
171+ # Call the plotting function, passing the axes
172+ if resp_fcn is not None :
173+ resp = resp_fcn (* args , ** kwargs )
174+ cplt4 = resp .plot (** kwargs , ** meth_kwargs , ax = ax )
175+ else :
176+ # No response function available; just plot the data
177+ cplt4 = plot_fcn (* args , ** kwargs , ** meth_kwargs , ax = ax )
178+
179+ # Check to make sure original settings did not change
180+ assert fig ._suptitle .get_text () == title
181+ assert fig ._suptitle .get_fontsize () == titlesize
182+ assert ax [0 ].get_yticklabels ()[0 ].get_fontsize () == labelsize
183+
139184
140185@pytest .mark .parametrize ("resp_fcn, plot_fcn" , resp_plot_fcns )
141186@pytest .mark .usefixtures ('mplcleanup' )
@@ -338,13 +383,13 @@ def test_plot_title_processing(resp_fcn, plot_fcn):
338383 case _:
339384 raise RuntimeError (f"didn't recognize { resp_fnc } , { plot_fnc } " )
340385
341- # Generate the first plot, with default labels
386+ # Generate the first plot, with default title
342387 cplt1 = plot_fcn (* args1 , ** kwargs , ** plot_fcn_kwargs )
343388 assert cplt1 .figure ._suptitle ._text .startswith (title_prefix )
344389
345390 # Skip functions not intended for sequential calling
346391 if plot_fcn not in nolabel_plot_fcns :
347- # Generate second plot with default labels
392+ # Generate second plot with default title
348393 cplt2 = plot_fcn (* args2 , ** kwargs , ** plot_fcn_kwargs )
349394 assert cplt1 .figure ._suptitle ._text == title_prefix + default_title
350395 plt .close ()
@@ -372,6 +417,11 @@ def test_plot_title_processing(resp_fcn, plot_fcn):
372417 assert cplt2 .figure ._suptitle ._text == "Another title"
373418 plt .close ()
374419
420+ # Generate the plots with no title
421+ cplt = plot_fcn (
422+ * args1 , ** kwargs , ** plot_fcn_kwargs , title = False )
423+ assert cplt .figure ._suptitle == None
424+
375425
376426@pytest .mark .usefixtures ('mplcleanup' )
377427def test_rcParams ():
0 commit comments