Skip to content

Commit b2087f3

Browse files
committed
Fix plotting response lists
1 parent 146ccee commit b2087f3

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

control/tests/timeplot_test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,34 @@ def test_combine_time_responses():
321321
ct.combine_time_responses([resp1, resp])
322322

323323

324+
@pytest.mark.usefixtures('mplcleanup')
325+
def test_time_response_plot_response_list():
326+
sys = ct.ss(ct.tf([1, 2], [3, 4, 5]))
327+
timepts = np.linspace(0, 10)
328+
resp1 = ct.input_output_response(sys, timepts, np.sin(timepts))
329+
resp2 = ct.input_output_response(sys, timepts, np.cos(timepts))
330+
331+
cplt = ct.time_response_plot(
332+
[resp1, resp2], trace_labels=["sine input", "cosine input"])
333+
assert cplt.lines.shape == (2, 2)
334+
assert cplt.axes[0, 0].get_title() == "sine input"
335+
assert cplt.axes[0, 1].get_title() == "cosine input"
336+
assert all(len(lines.item()) == 1 for lines in np.nditer(
337+
cplt.lines, flags=["refs_ok"]))
338+
plt.close()
339+
340+
cplt = ct.time_response_plot([resp1, resp2], plot_inputs=True)
341+
assert cplt.lines.shape == (2, 2)
342+
assert all(len(lines.item()) == 1 for lines in np.nditer(
343+
cplt.lines, flags=["refs_ok"]))
344+
plt.close()
345+
346+
cplt = ct.time_response_plot([resp1, resp2], plot_inputs='overlay')
347+
assert cplt.lines.shape == (1, 2)
348+
assert all(len(lines.item()) == 2 for lines in np.nditer(
349+
cplt.lines, flags=["refs_ok"]))
350+
351+
324352
@pytest.mark.parametrize("resp_fcn", [
325353
ct.step_response, ct.initial_response, ct.impulse_response,
326354
ct.forced_response, ct.input_output_response])

control/timeplot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def time_response_plot(
5252
5353
Parameters
5454
----------
55-
data : `TimeResponseData`
56-
Data to be plotted.
55+
data : `TimeResponseData` or list of `TimeResponseData`
56+
Data to be plotted. Lists of responses are combined into a
57+
multi-trace response before plotting.
5758
plot_inputs : bool or str, optional
5859
Sets how and where to plot the inputs:
5960
* False: don't plot the inputs
@@ -179,6 +180,9 @@ def time_response_plot(
179180
#
180181
# Process keywords and set defaults
181182
#
183+
if isinstance(data, (list, tuple)):
184+
data = combine_time_responses(data, trace_labels=trace_labels)
185+
182186
# Set up defaults
183187
ax_user = ax
184188
sharex = config._get_param('timeplot', 'sharex', kwargs, pop=True)

0 commit comments

Comments
 (0)