-
Notifications
You must be signed in to change notification settings - Fork 438
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update pole/zero and root locus plots to use _map/_plot pattern #953
Conversation
control/sisotool.py
Outdated
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import warnings | ||
from functools import partial |
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.
control/tests/pzmap_test.py
Outdated
# 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()) |
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?
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.
This PR updates pole/zero and root locus plots to use the _map/_plot calling pattern described in #645. The following patterns will work:
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:
_map
function and a_plot
function. You can access the latter via the.plot()
method on the response._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.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.print_gain
keyword is replaced withinteractive
.Plot
keyword is nowplot
(and generates a warning, since it triggers the legacy return values).pzmap
andrlocus
are still there.control.matlab
version ofrlocus
returnsroots, gains
(compatible with MATLAB)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:A root locus plot shows the location of the closed loop poles of a system as a function of the loop gain:
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 toFals
e 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:
Root locus diagrams are also supported for discrete time systems, in which case the grid is show inside the unit circle:
Lists of systems can also be given, in which case the root locus diagram for each system is plotted in different colors: