27
27
# @pytest.mark.parametrize("transpose", [False, True])
28
28
# @pytest.mark.parametrize("plot_inputs", [False, None, True, 'overlay'])
29
29
# @pytest.mark.parametrize("plot_outputs", [True, False])
30
- # @pytest.mark.parametrize("combine_signals ", [False, True])
31
- # @pytest.mark.parametrize("combine_traces ", [False, True])
30
+ # @pytest.mark.parametrize("overlay_signals ", [False, True])
31
+ # @pytest.mark.parametrize("overlay_traces ", [False, True])
32
32
# @pytest.mark.parametrize("second_system", [False, True])
33
33
# @pytest.mark.parametrize("fcn", [
34
34
# ct.step_response, ct.impulse_response, ct.initial_response,
@@ -90,7 +90,7 @@ def test_response_plots(
90
90
# Save up the keyword arguments
91
91
kwargs = dict (
92
92
plot_inputs = pltinp , plot_outputs = pltout , transpose = trpose ,
93
- combine_signals = cmbsig , combine_traces = cmbtrc )
93
+ overlay_signals = cmbsig , overlay_traces = cmbtrc )
94
94
95
95
# Create the response
96
96
if fcn is ct .input_output_response and \
@@ -189,7 +189,7 @@ def test_response_plots(
189
189
190
190
191
191
def test_axes_setup ():
192
- get_axes = ct .timeplot .get_axes
192
+ get_plot_axes = ct .timeplot .get_plot_axes
193
193
194
194
sys_2x3 = ct .rss (4 , 2 , 3 )
195
195
sys_2x3b = ct .rss (4 , 2 , 3 )
@@ -199,36 +199,36 @@ def test_axes_setup():
199
199
# Two plots of the same size leaves axes unchanged
200
200
out1 = ct .step_response (sys_2x3 ).plot ()
201
201
out2 = ct .step_response(sys_2x3b ).plot ()
202
- np .testing .assert_equal (get_axes (out1 ), get_axes (out2 ))
202
+ np .testing .assert_equal (get_plot_axes (out1 ), get_plot_axes (out2 ))
203
203
plt .close ()
204
204
205
205
# Two plots of same net size leaves axes unchanged (unfortunately)
206
206
out1 = ct .step_response (sys_2x3 ).plot ()
207
207
out2 = ct .step_response (sys_3x2 ).plot ()
208
208
np .testing .assert_equal (
209
- get_axes (out1 ).reshape (- 1 ), get_axes (out2 ).reshape (- 1 ))
209
+ get_plot_axes (out1 ).reshape (- 1 ), get_plot_axes (out2 ).reshape (- 1 ))
210
210
plt .close ()
211
211
212
212
# Plots of different shapes generate new plots
213
213
out1 = ct .step_response (sys_2x3 ).plot ()
214
214
out2 = ct .step_response (sys_3x1 ).plot ()
215
- ax1_list = get_axes (out1 ).reshape (- 1 ).tolist ()
216
- ax2_list = get_axes (out2 ).reshape (- 1 ).tolist ()
215
+ ax1_list = get_plot_axes (out1 ).reshape (- 1 ).tolist ()
216
+ ax2_list = get_plot_axes (out2 ).reshape (- 1 ).tolist ()
217
217
for ax in ax1_list :
218
218
assert ax not in ax2_list
219
219
plt .close ()
220
220
221
221
# Passing a list of axes preserves those axes
222
222
out1 = ct .step_response (sys_2x3 ).plot ()
223
223
out2 = ct .step_response (sys_3x1 ).plot ()
224
- out3 = ct .step_response (sys_2x3b ).plot (ax = get_axes (out1 ))
225
- np .testing .assert_equal (get_axes (out1 ), get_axes (out3 ))
224
+ out3 = ct .step_response (sys_2x3b ).plot (ax = get_plot_axes (out1 ))
225
+ np .testing .assert_equal (get_plot_axes (out1 ), get_plot_axes (out3 ))
226
226
plt .close ()
227
227
228
228
# Sending an axes array of the wrong size raises exception
229
229
with pytest .raises (ValueError , match = "not the right shape" ):
230
230
out = ct .step_response (sys_2x3 ).plot ()
231
- ct .step_response (sys_3x1 ).plot (ax = get_axes (out ))
231
+ ct .step_response (sys_3x1 ).plot (ax = get_plot_axes (out ))
232
232
sys_2x3 = ct .rss (4 , 2 , 3 )
233
233
sys_2x3b = ct .rss (4 , 2 , 3 )
234
234
sys_3x2 = ct .rss (4 , 3 , 2 )
@@ -244,7 +244,7 @@ def test_legend_map():
244
244
response .plot (
245
245
legend_map = np .array ([['center' , 'upper right' ],
246
246
[None , 'center right' ]]),
247
- plot_inputs = True , combine_signals = True , transpose = True ,
247
+ plot_inputs = True , overlay_signals = True , transpose = True ,
248
248
title = 'MIMO step response with custom legend placement' )
249
249
250
250
@@ -310,18 +310,55 @@ def test_combine_traces():
310
310
combresp6 = ct .combine_traces ([resp1 , resp ])
311
311
312
312
313
+ def test_linestyles ():
314
+ # Check to make sure we can change line styles
315
+ sys_mimo = ct .tf2ss (
316
+ [[[1 ], [0.1 ]], [[0.2 ], [1 ]]],
317
+ [[[1 , 0.6 , 1 ], [1 , 1 , 1 ]], [[1 , 0.4 , 1 ], [1 , 2 , 1 ]]], name = "MIMO" )
318
+ out = ct .step_response (sys_mimo ).plot ('k--' , plot_inputs = True )
319
+ for ax in np .nditer (out , flags = ["refs_ok" ]):
320
+ for line in ax .item ():
321
+ assert line .get_color () == 'k'
322
+ assert line .get_linestyle () == '--'
323
+
324
+
325
+ def test_relabel ():
326
+ sys1 = ct .rss (2 , inputs = 'u' , outputs = 'y' )
327
+ sys2 = ct .rss (1 , 1 , 1 ) # uses default i/o labels
328
+
329
+ # Generate a plot with specific labels
330
+ ct .step_response (sys1 ).plot ()
331
+
332
+ # Generate a new plot, which overwrites labels
333
+ out = ct .step_response (sys2 ).plot ()
334
+ ax = ct .get_plot_axes (out )
335
+ assert ax [0 , 0 ].get_ylabel () == 'y[0]'
336
+
337
+ # Regenerate the first plot
338
+ plt .figure ()
339
+ ct .step_response (sys1 ).plot ()
340
+
341
+ # Generate a new plt, without relabeling
342
+ out = ct .step_response (sys2 ).plot (relabel = False )
343
+ ax = ct .get_plot_axes (out )
344
+ assert ax [0 , 0 ].get_ylabel () == 'y'
345
+
346
+
313
347
def test_errors ():
314
348
sys = ct .rss (2 , 1 , 1 )
315
349
stepresp = ct .step_response (sys )
316
- with pytest .raises (TypeError , match = "unrecognized keyword" ):
350
+ with pytest .raises (AttributeError ,
351
+ match = "(has no property|unexpected keyword)" ):
317
352
stepresp .plot (unknown = None )
318
353
319
- with pytest .raises (TypeError , match = "unrecognized keyword" ):
354
+ with pytest .raises (AttributeError ,
355
+ match = "(has no property|unexpected keyword)" ):
320
356
ct .time_response_plot (stepresp , unknown = None )
321
357
322
358
with pytest .raises (ValueError , match = "unrecognized value" ):
323
359
stepresp .plot (plot_inputs = 'unknown' )
324
360
361
+
325
362
if __name__ == "__main__" :
326
363
#
327
364
# Interactive mode: generate plots for manual viewing
@@ -344,8 +381,8 @@ def test_errors():
344
381
345
382
# Define and run a selected set of interesting tests
346
383
# def test_response_plots(
347
- # fcn, sys, plot_inputs, plot_outputs, combine_signals ,
348
- # combine_traces , transpose, second_system, clear=True):
384
+ # fcn, sys, plot_inputs, plot_outputs, overlay_signals ,
385
+ # overlay_traces , transpose, second_system, clear=True):
349
386
N , T , F = None , True , False
350
387
test_cases = [
351
388
# response fcn system in out cs ct tr ss
@@ -379,12 +416,12 @@ def test_errors():
379
416
ct .step_response (sys_mimo ).plot ()
380
417
plt .savefig ('timeplot-mimo_step-default.png' )
381
418
382
- # Step response with plot_inputs, combine_signals
419
+ # Step response with plot_inputs, overlay_signals
383
420
plt .figure ()
384
421
ct .step_response (sys_mimo ).plot (
385
- plot_inputs = True , combine_signals = True ,
422
+ plot_inputs = True , overlay_signals = True ,
386
423
title = "Step response for 2x2 MIMO system " +
387
- "[plot_inputs, combine_signals ]" )
424
+ "[plot_inputs, overlay_signals ]" )
388
425
plt .savefig ('timeplot-mimo_step-pi_cs.png' )
389
426
390
427
# Input/output response with overlaid inputs, legend_map
@@ -412,3 +449,9 @@ def test_errors():
412
449
title = "I/O responses for 2x2 MIMO system, multiple traces "
413
450
"[transpose]" )
414
451
plt .savefig ('timeplot-mimo_ioresp-mt_tr.png' )
452
+
453
+ # Reset line styles
454
+ plt .figure ()
455
+ resp1 .plot ('g-' )
456
+ resp2 .plot ('r--' )
457
+ # plt.savefig('timeplot-mimo_step-linestyle.png')
0 commit comments