Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 23 additions & 0 deletions control/tests/timeplot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,29 @@ def test_list_responses(resp_fcn):
assert cplt.lines[row, col][1].get_color() == 'tab:orange'


@pytest.mark.parametrize("plot_inputs, shape", [
(None, (2, 1)), (True, (2, 1)), ('overlay', (1, 1)), (False, (1, 1))])
@pytest.mark.usefixtures('mplcleanup')
def test_time_response_plot_list(plot_inputs, shape):
# A list of responses is plotted like a TimeResponseList (gh-1171)
sys = ct.ss(ct.tf([1, 2], [3, 4, 5]))
timepts = np.linspace(0, 10)
resp1 = ct.input_output_response(sys, timepts, np.sin(timepts))
resp2 = ct.input_output_response(sys, timepts, np.cos(timepts))

cplt = ct.time_response_plot([resp1, resp2], plot_inputs=plot_inputs)
assert cplt.lines.shape == shape

plt.figure()
cplt_list = ct.TimeResponseList([resp1, resp2]).plot(
plot_inputs=plot_inputs)
assert cplt_list.lines.shape == shape
for lines, lines_list in zip(cplt.lines.flat, cplt_list.lines.flat):
assert len(lines) == len(lines_list)
for line, line_list in zip(lines, lines_list):
np.testing.assert_equal(line.get_ydata(), line_list.get_ydata())


@pytest.mark.slycot
@pytest.mark.usefixtures('mplcleanup')
def test_linestyles():
Expand Down
16 changes: 14 additions & 2 deletions control/timeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def time_response_plot(

Parameters
----------
data : `TimeResponseData`
Data to be plotted.
data : `TimeResponseData` or list of `TimeResponseData`
Data to be plotted. The responses in a list are plotted on the
same axes, as `TimeResponseList.plot` does.
plot_inputs : bool or str, optional
Sets how and where to plot the inputs:
* False: don't plot the inputs
Expand Down Expand Up @@ -175,6 +176,17 @@ def time_response_plot(

"""
from .ctrlplot import _process_ax_keyword, _process_line_labels
from .timeresp import TimeResponseList

# Plot a list of responses one at a time, as `TimeResponseList.plot` does
if isinstance(data, (list, tuple)):
if label is not None:
kwargs['label'] = label
return TimeResponseList(data).plot(
*fmt, ax=ax, plot_inputs=plot_inputs, plot_outputs=plot_outputs,
transpose=transpose, overlay_traces=overlay_traces,
overlay_signals=overlay_signals, add_initial_zero=add_initial_zero,
trace_labels=trace_labels, title=title, relabel=relabel, **kwargs)

#
# Process keywords and set defaults
Expand Down