GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update pole/zero and root locus plots to use _map/_plot pattern by murrayrm · Pull Request #953 · python-control/python-control

Conversation

@murrayrm

@murrayrm murrayrm commented Dec 29, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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 the plot 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 of pole_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 within sisotool). 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.
  • The print_gain keyword is replaced with interactive.
  • The (deprecated) Plot keyword is now plot (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 versions pzmap and rlocus are still there.
  • The control.matlab version of rlocus returns roots, 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. The pole_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 the grid keyword. Setting grid to False will turn off the grid but show the real and imaginary axis. To completely remove all lines except the root loci, use grid=’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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
murrayrm added 13 commits December 28, 2023 12:41
@murrayrm
refactoring of pzmap into response/plot + unit test changes
6b5cafc
@murrayrm
pz -> pole_zero + add loci plotting
1451f3a
@murrayrm
remove sisotool dependencies in rlocus
1390e37
@murrayrm
update xlim, ylim handling in pzmap + other supporting changes
6e33598
@murrayrm
reorder ct.isdtime parameters for backward compatibility
1c4322c
@murrayrm
initial refactoring of root_locus_{map,plot}
57dac87
@murrayrm
adjust root locus spacing and add scaling keyword
ee46ac6
@murrayrm
tweak grid processing, add documentation, interactive by default
0d23598
@murrayrm
add legacy processing for root_locus
0137056
@murrayrm
add backward compatibility for matlab.{rlocus,pzmap} + suppress warnings
08e55b1
@murrayrm
updated grid handling (add 'empty')
8776875
@murrayrm
updated rlocus/pzmap docs, docstrings, tests
416dff8
@murrayrm
updated unit test for coverage + some fixes
52f8127
@murrayrm murrayrm mentioned this pull request Dec 29, 2023
Version 0.10 changes (tracking issue) #917
Closed
7 tasks done
@coveralls

coveralls commented Dec 29, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Coverage Status

coverage: 94.866% (-0.1%) from 94.989%
when pulling f500cbe on murrayrm:pzmap_plots-22Jul2023
into b389b64 on python-control:main.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@murrayrm murrayrm mentioned this pull request Dec 29, 2023
Fix CI warnings #955
Merged
@murrayrm murrayrm added this to the 0.10.0 milestone Dec 30, 2023
@murrayrm
fix initial_gain in documentation example
5ca2d5c
bnavigator
bnavigator reviewed Jan 10, 2024
View reviewed changes
Comment thread control/sisotool.py Outdated
Comment on lines +3 to +6
import numpy as np
import matplotlib.pyplot as plt
import warnings
from functools import partial

@bnavigator bnavigator Jan 10, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Worth running this through isort?

warnings and functools are stdlib, Numpy and Pyplot external.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
bnavigator
bnavigator reviewed Jan 10, 2024
View reviewed changes
Comment thread control/tests/pzmap_test.py Outdated
Comment on lines +97 to +106
# Legacy return format
with pytest.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())

with pytest.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())

@bnavigator bnavigator Jan 10, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Parametrize?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
bnavigator
bnavigator approved these changes Jan 10, 2024
View reviewed changes

@bnavigator bnavigator left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
murrayrm added 2 commits January 11, 2024 21:11
@murrayrm
isort files
d532dc9
@murrayrm
parametrize test per @bnavigator suggestion
f500cbe
@murrayrm
murrayrm merged commit eb0f3f9 into python-control:main Jan 12, 2024
@murrayrm
murrayrm deleted the pzmap_plots-22Jul2023 branch January 12, 2024 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bnavigator bnavigator bnavigator approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

0.10.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@murrayrm @coveralls @bnavigator
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.