Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add support for plot_input='overlay', trace labeling, legend processing
  • Loading branch information
murrayrm committed Jul 10, 2023
commit dacf17c87e13aa2e6d33c2f9fb706215800eeb2b
4 changes: 3 additions & 1 deletion control/nlsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,7 @@ def ufun(t):
return TimeResponseData(
t_eval, y, None, u, issiso=sys.issiso(),
output_labels=sys.output_labels, input_labels=sys.input_labels,
title="Input/output response for " + sys.name, sysname=sys.name,
transpose=transpose, return_x=return_x, squeeze=squeeze)

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


Expand Down
3 changes: 3 additions & 0 deletions control/tests/kwargs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import control.tests.statefbk_test as statefbk_test
import control.tests.stochsys_test as stochsys_test
import control.tests.trdata_test as trdata_test
import control.tests.timeplot_test as timeplot_test

@pytest.mark.parametrize("module, prefix", [
(control, ""), (control.flatsys, "flatsys."), (control.optimal, "optimal.")
Expand Down Expand Up @@ -185,6 +186,7 @@ def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
'gangof4_plot': test_matplotlib_kwargs,
'input_output_response': test_unrecognized_kwargs,
'interconnect': interconnect_test.test_interconnect_exceptions,
'ioresp_plot': timeplot_test.test_errors,
'linearize': test_unrecognized_kwargs,
'lqe': test_unrecognized_kwargs,
'lqr': test_unrecognized_kwargs,
Expand Down Expand Up @@ -230,6 +232,7 @@ def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
'StateSpace.__init__': test_unrecognized_kwargs,
'StateSpace.sample': test_unrecognized_kwargs,
'TimeResponseData.__call__': trdata_test.test_response_copy,
'TimeResponseData.plot': timeplot_test.test_errors,
'TransferFunction.__init__': test_unrecognized_kwargs,
'TransferFunction.sample': test_unrecognized_kwargs,
'optimal.OptimalControlProblem.__init__':
Expand Down
28 changes: 23 additions & 5 deletions control/tests/timeplot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@
# Step responses
@pytest.mark.parametrize("nin, nout", [(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)])
@pytest.mark.parametrize("transpose", [True, False])
@pytest.mark.parametrize("plot_inputs", [None, True, False])
@pytest.mark.parametrize("plot_inputs", [None, True, False, 'overlay'])
def test_simple_response(nout, nin, transpose, plot_inputs):
sys = ct.rss(4, nout, nin)
stepresp = ct.step_response(sys)
stepresp.plot(plot_inputs=plot_inputs, transpose=transpose)

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

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

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


def test_errors():
sys = ct.rss(2, 1, 1)
stepresp = ct.step_response(sys)
with pytest.raises(TypeError, match="unrecognized keyword"):
stepresp.plot(unknown=None)

with pytest.raises(TypeError, match="unrecognized keyword"):
ct.ioresp_plot(stepresp, unknown=None)

with pytest.raises(ValueError, match="unrecognized value"):
stepresp.plot(plot_inputs='unknown')


if __name__ == "__main__":
#
# Interactive mode: generate plots for manual viewing
Expand All @@ -66,7 +84,7 @@ def test_combine_signals_traces(transpose):
print ("Simple step responses")
for size in [(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)]:
for transpose in [False, True]:
for plot_inputs in [None, True, False]:
for plot_inputs in [None, True, False, 'overlay']:
plt.figure()
test_simple_response(
*size, transpose=transpose, plot_inputs=plot_inputs)
Expand Down
Loading