Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Time response plots#920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
murrayrm merged 12 commits intopython-control:mainfrommurrayrm:time_plots-20Jun2023
Jul 13, 2023

Conversation

murrayrm
Copy link
Member

@murrayrmmurrayrm commentedJul 3, 2023
edited
Loading

This PR implements time response plots for the various simulation routines in python-control via a new functiontime_response_plot() and via theplot() method on theTimeResponseData class. This is aligned with the new plotting paradigm in#645.

Examples (from the user documentation):

Input/output time responses are produced using one of several python-control functions:forced_response,impulse_response,initial_response(),input_output_response(), andstep_response(). Each of these return aTimeResponseData object, which contains the time, input, state, and output vectors associated with the simulation. Time response data can be plotted with thetime_response_plot() function, which is also available as theplot() method. For example, the step response for a two-input, two-output can be plotted using the commands:

sys_mimo = ct.tf2ss(    [[[1], [0.1]], [[0.2], [1]]],    [[[1, 0.6, 1], [1, 1, 1]], [[1, 0.4, 1], [1, 2, 1]]], name="MIMO")response = step_response(sys)response.plot()

which produces the following plot:

timeplot-mimo_step-default

TheTimeResponseData object can also be used to access the data from the simulation:

time, outputs, inputs = response.time, response.outputs, response.inputsfig, axs = plt.subplots(2, 2)for i in range(2):    for j in range(2):        axs[i, j].plot(time, outputs[i, j])

A number of options are available in the plot method to customize the appearance of input output data. For data produced by theimpulse_response() andstep_response() commands, the inputs are not shown. This behavior can be changed using theplot_inputs keyword. It is also possible to combine multiple lines onto a single graph, using either theoverlay_signals keyword (which puts all outputs out a single graph and all inputs on a single graph) or theoverlay_traces keyword, which puts different traces (e.g., corresponding to step inputs in different channels) on the same graph, with appropriate labeling via a legend on selected axes.

For example, usingplot_input=True andoverlay_signals=True yields the following plot:

ct.step_response(sys_mimo).plot(  plot_inputs=True, overlay_signals=True,  title="Step response for 2x2 MIMO system " +  "[plot_inputs, overlay_signals]")

timeplot-mimo_step-pi_cs

Input/output response plots created with either theforced_response() or theinput_output_response() functions include the input signals by default. These can be plotted on separate axes, but also “overlaid” on the output axes (useful when the input and output signals are being compared to each other). The following plot shows the use ofplot_inputs=’overlay’ as well as the ability to reposition the legends using thelegend_map keyword:

timepts = np.linspace(0, 10, 100)U = np.vstack([np.sin(timepts), np.cos(2*timepts)])ct.input_output_response(sys_mimo, timepts, U).plot(    plot_inputs='overlay',    legend_map=np.array([['lower right'], ['lower right']]),    title="I/O response for 2x2 MIMO system " +    "[plot_inputs='overlay', legend_map]")

timeplot-mimo_ioresp-ov_lm

Another option that is available is to use the transpose keyword so that instead of plotting the outputs on the top and inputs on the bottom, the inputs are plotted on the left and outputs on the right, as shown in the following figure:

U1 = np.vstack([np.sin(timepts), np.cos(2*timepts)])resp1 = ct.input_output_response(sys_mimo, timepts, U1)U2 = np.vstack([np.cos(2*timepts), np.sin(timepts)])resp2 = ct.input_output_response(sys_mimo, timepts, U2)ct.combine_traces(    [resp1, resp2], trace_labels=["Scenario #1", "Scenario #2"]).plot(        transpose=True,        title="I/O responses for 2x2 MIMO system, multiple traces "        "[transpose]")

timeplot-mimo_ioresp-mt_tr

This figure also illustrates the ability to create “multi-trace” plots using thecombine_traces() function.

Additional customization is possible using theinput_props,output_props andtrace_props keywords to set complementary line colors and styles for various signals and traces:

out = ct.step_response(sys_mimo).plot(    plot_inputs='overlay', overlay_signals=True, overlay_traces=True,    output_props=[{'color': c} for c in ['blue', 'orange']],    input_props=[{'color': c} for c in ['red', 'green']],    trace_props=[{'linestyle': s} for s in ['-', '--']])

timeplot-mimo_step-linestyle

@murrayrmmurrayrm marked this pull request as draftJuly 3, 2023 01:23
@murrayrmmurrayrm mentioned this pull requestJul 3, 2023
7 tasks
@coveralls
Copy link

coveralls commentedJul 3, 2023
edited
Loading

Coverage Status

coverage: 94.968% (+0.1%) from 94.849% when pullingbab5071 on murrayrm:time_plots-20Jun2023 intoa8658e4 on python-control:main.

@murrayrmmurrayrm marked this pull request as ready for reviewJuly 10, 2023 04:36
@sawyerbfuller
Copy link
Contributor

Looks pretty comprehensive and pretty good to me. I particuarly like that this makes it much quicker to plot the inputs and outputs of a mimo system.

@murrayrmmurrayrm merged commit42c6fb1 intopython-control:mainJul 13, 2023
@murrayrmmurrayrm added this to the0.10.0 milestoneMar 31, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
0.10.0
Development

Successfully merging this pull request may close these issues.

3 participants
@murrayrm@coveralls@sawyerbfuller

[8]ページ先頭

©2009-2025 Movatter.jp