Skip to content

Commit dacf17c

Browse files
committed
add support for plot_input='overlay', trace labeling, legend processing
1 parent ece5f92 commit dacf17c

5 files changed

Lines changed: 359 additions & 106 deletions

File tree

control/nlsys.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,7 @@ def ufun(t):
14881488
return TimeResponseData(
14891489
t_eval, y, None, u, issiso=sys.issiso(),
14901490
output_labels=sys.output_labels, input_labels=sys.input_labels,
1491+
title="Input/output response for " + sys.name, sysname=sys.name,
14911492
transpose=transpose, return_x=return_x, squeeze=squeeze)
14921493

14931494
# Create a lambda function for the right hand side
@@ -1567,7 +1568,8 @@ def ivp_rhs(t, x):
15671568
return TimeResponseData(
15681569
soln.t, y, soln.y, u, issiso=sys.issiso(),
15691570
output_labels=sys.output_labels, input_labels=sys.input_labels,
1570-
state_labels=sys.state_labels,
1571+
state_labels=sys.state_labels, sysname=sys.name,
1572+
title="Input/output response for " + sys.name,
15711573
transpose=transpose, return_x=return_x, squeeze=squeeze)
15721574

15731575

control/tests/kwargs_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import control.tests.statefbk_test as statefbk_test
2727
import control.tests.stochsys_test as stochsys_test
2828
import control.tests.trdata_test as trdata_test
29+
import control.tests.timeplot_test as timeplot_test
2930

3031
@pytest.mark.parametrize("module, prefix", [
3132
(control, ""), (control.flatsys, "flatsys."), (control.optimal, "optimal.")
@@ -185,6 +186,7 @@ def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
185186
'gangof4_plot': test_matplotlib_kwargs,
186187
'input_output_response': test_unrecognized_kwargs,
187188
'interconnect': interconnect_test.test_interconnect_exceptions,
189+
'ioresp_plot': timeplot_test.test_errors,
188190
'linearize': test_unrecognized_kwargs,
189191
'lqe': test_unrecognized_kwargs,
190192
'lqr': test_unrecognized_kwargs,
@@ -230,6 +232,7 @@ def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
230232
'StateSpace.__init__': test_unrecognized_kwargs,
231233
'StateSpace.sample': test_unrecognized_kwargs,
232234
'TimeResponseData.__call__': trdata_test.test_response_copy,
235+
'TimeResponseData.plot': timeplot_test.test_errors,
233236
'TransferFunction.__init__': test_unrecognized_kwargs,
234237
'TransferFunction.sample': test_unrecognized_kwargs,
235238
'optimal.OptimalControlProblem.__init__':

control/tests/timeplot_test.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@
99
# Step responses
1010
@pytest.mark.parametrize("nin, nout", [(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)])
1111
@pytest.mark.parametrize("transpose", [True, False])
12-
@pytest.mark.parametrize("plot_inputs", [None, True, False])
12+
@pytest.mark.parametrize("plot_inputs", [None, True, False, 'overlay'])
1313
def test_simple_response(nout, nin, transpose, plot_inputs):
1414
sys = ct.rss(4, nout, nin)
1515
stepresp = ct.step_response(sys)
1616
stepresp.plot(plot_inputs=plot_inputs, transpose=transpose)
1717

1818
# Add additional data (and provide infon in the title)
19-
ct.step_response(ct.rss(4, nout, nin), stepresp.time[-1]).plot(
20-
plot_inputs=plot_inputs, transpose=transpose,
21-
title=stepresp.title + f" [{plot_inputs=}, {transpose=}]")
19+
newsys = ct.rss(4, nout, nin)
20+
out = ct.step_response(newsys, stepresp.time[-1]).plot(
21+
plot_inputs=plot_inputs, transpose=transpose)
2222

23+
# Update the title so we can see what is going on
24+
fig = out[0, 0][0].axes.figure
25+
fig.suptitle(
26+
fig._suptitle._text + f" [{nout}x{nin}, {plot_inputs=}, {transpose=}]",
27+
fontsize='small')
2328

2429
@pytest.mark.parametrize("transpose", [True, False])
2530
def test_combine_signals(transpose):
@@ -49,6 +54,19 @@ def test_combine_signals_traces(transpose):
4954
f"transpose={transpose}")
5055

5156

57+
def test_errors():
58+
sys = ct.rss(2, 1, 1)
59+
stepresp = ct.step_response(sys)
60+
with pytest.raises(TypeError, match="unrecognized keyword"):
61+
stepresp.plot(unknown=None)
62+
63+
with pytest.raises(TypeError, match="unrecognized keyword"):
64+
ct.ioresp_plot(stepresp, unknown=None)
65+
66+
with pytest.raises(ValueError, match="unrecognized value"):
67+
stepresp.plot(plot_inputs='unknown')
68+
69+
5270
if __name__ == "__main__":
5371
#
5472
# Interactive mode: generate plots for manual viewing
@@ -66,7 +84,7 @@ def test_combine_signals_traces(transpose):
6684
print ("Simple step responses")
6785
for size in [(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)]:
6886
for transpose in [False, True]:
69-
for plot_inputs in [None, True, False]:
87+
for plot_inputs in [None, True, False, 'overlay']:
7088
plt.figure()
7189
test_simple_response(
7290
*size, transpose=transpose, plot_inputs=plot_inputs)

0 commit comments

Comments
 (0)