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

Update pole/zero and root locus plots to use _map/_plot pattern#953

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 16 commits intopython-control:mainfrommurrayrm:pzmap_plots-22Jul2023
Jan 12, 2024

Conversation

@murrayrm
Copy link
Member

@murrayrmmurrayrm commentedDec 29, 2023
edited
Loading

This PR updates pole/zero and root locus plots to use the _map/_plot calling pattern described in#645. The following patterns will work:

rldata = ct.root_locus_map(syslist[, klist])lines = rldata.plot(plot_options)lines = ct.root_locus_plot(response[, klist, plot_options])ct.root_locus(sys)ct.rlocus(sys)ct.pole_zero_map(sys).plot()ct.pole_zero_plot(sys)ct.pzmap(sys)

Everything is mostly backwards compatible except that the outputs from a _plot function are now an array of Line2D objects instead of the roots and gains. You can still get the original data using the _map function and there is some legacy processing if you used theplot keyword to try let some code work without changes.

Summary of changes:

  • All pole/zero and root locus plots now have a_map function and a_plot function. You can access the latter via the.plot() method on the response.
  • The_plot functions accept either the output of the_map function or a list of systems (in which case the_map function is called internally). This allows the common pattern ofpole_zero_plot(sys),root_locus_plot(sys) to work as expected.
  • The interactive mode for root locus plots is on by default (it used to be there only withinsisotool). Clicking on a portion of the root locus diagram will generate markers at the locations on the loci corresponding to that gain and add a message above the plot giving the frequency and damping ratio for the point that was clicked.
  • Theprint_gain keyword is replaced withinteractive.
  • The (deprecated)Plot keyword is nowplot (and generates a warning, since it triggers the legacy return values).
  • Recalculation of the root locus plot when zooming no longer works (you can still zoom in and out, you just don't get a recalculated curve).
  • The short versionspzmap andrlocus are still there.
  • Thecontrol.matlab version ofrlocus returnsroots, gains (compatible with MATLAB)
  • Added unit tests plus user documentation.
  • Some other small fixes, code streamlining, etc along the way.

This PR is going to break existing code. It would be great if a few people could try this out so that we can make sure we are OK with the changes here.

Examples (from the user documentation):

Pole/zero maps and root locus diagrams provide insights into system response based on the locations of system poles and zeros in the complex plane. Thepole_zero_map() function returns the poles and zeros and can be used to generate a pole/zero plot:

sys = ct.tf([1, 2], [1, 2, 3], name='SISO transfer function')response = ct.pole_zero_map(sys)ct.pole_zero_plot(response)

pzmap-siso_ctime-default

A root locus plot shows the location of the closed loop poles of a system as a function of the loop gain:

ct.root_locus_map(sys).plot()

rlocus-siso_ctime-default

The grid in the left hand plane shows lines of constant damping ratio as well as arcs corresponding to the frequency of the complex pole. The grid can be turned off using thegrid keyword. Setting grid toFalse will turn off the grid but show the real and imaginary axis. To completely remove all lines except the root loci, usegrid=’empty’.

On systems that support interactive plots, clicking on a location on the root locus diagram will mark the pole locations on all branches of the diagram and display the gain and damping ratio below the plot title:

rlocus-siso_ctime-clicked

Root locus diagrams are also supported for discrete time systems, in which case the grid is show inside the unit circle:

sysd = sys.sample(0.1)ct.root_locus_plot(sysd)

rlocus-siso_dtime-default

Lists of systems can also be given, in which case the root locus diagram for each system is plotted in different colors:

sys1 = ct.tf([1], [1, 2, 1], name='sys1')sys2 = ct.tf([1, 0.2], [1, 1, 3, 1, 1], name='sys2')ct.root_locus_plot([sys1, sys2], grid=False)

rlocus-siso_multiple-nogrid

@murrayrmmurrayrm mentioned this pull requestDec 29, 2023
7 tasks
@coveralls
Copy link

coveralls commentedDec 29, 2023
edited
Loading

Coverage Status

coverage: 94.866% (-0.1%) from 94.989%
when pullingf500cbe on murrayrm:pzmap_plots-22Jul2023
intob389b64 on python-control:main.

@murrayrmmurrayrm mentioned this pull requestDec 29, 2023
@murrayrmmurrayrm added this to the0.10.0 milestoneDec 30, 2023
Comment on lines 3 to 6
importnumpyasnp
importmatplotlib.pyplotasplt
importwarnings
fromfunctoolsimportpartial
Copy link
Contributor

@bnavigatorbnavigatorJan 10, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Worth running this throughisort?

warnings andfunctools are stdlib, Numpy and Pyplot external.

Comment on lines 97 to 106
# Legacy return format
withpytest.warns(DeprecationWarning,match=".* values .* deprecated"):
poles,zeros=ct.pole_zero_plot(pzdata,plot=False)
np.testing.assert_equal(poles,sys.poles())
np.testing.assert_equal(zeros,sys.zeros())

withpytest.warns(DeprecationWarning,match=".* values .* deprecated"):
poles,zeros=ct.pole_zero_plot(pzdata,plot=True)
np.testing.assert_equal(poles,sys.poles())
np.testing.assert_equal(zeros,sys.zeros())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Parametrize?

Copy link
Contributor

@bnavigatorbnavigator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is large, without too extensive review, I would say LGTM.

@murrayrmmurrayrm merged commiteb0f3f9 intopython-control:mainJan 12, 2024
@murrayrmmurrayrm deleted the pzmap_plots-22Jul2023 branchJanuary 12, 2024 05:32
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@bnavigatorbnavigatorbnavigator approved these changes

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@bnavigator

[8]ページ先頭

©2009-2025 Movatter.jp