Skip to content

make it so rlocus does not always create a new figure, so it is like matlab and control.sisotool #413

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

Merged
merged 5 commits into from
Jul 11, 2020
Merged

Conversation

sawyerbfuller
Copy link
Contributor

rlocus did not have a way to do anything other than always create a new figure.

  • to be more like matlab and more flexible, now it re-uses the current figure by default
  • new argument to specify a figure to use instead of the current figure if desired

…ne, similar to matlab behavior. new argument in rlocus to specify figure to plot in
@coveralls
Copy link

coveralls commented Jun 3, 2020

Coverage Status

Coverage increased (+0.2%) to 84.371% when pulling 4745b5c on sawyerbfuller:rlocus-no-new-figure into 03183d1 on python-control:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 84.064% when pulling 8743692 on sawyerbfuller:rlocus-no-new-figure into 03183d1 on python-control:master.

@@ -71,7 +71,8 @@

# Main function: compute a root locus diagram
def root_locus(sys, kvect=None, xlim=None, ylim=None,
plotstr=None, plot=True, print_gain=None, grid=None, **kwargs):
plotstr=None, plot=True, print_gain=None, grid=None, fig=None,
**kwargs):

Choose a reason for hiding this comment

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

If you are going to add this option I think it is much better to pass in the matplotlib axes to plot on, not the figure. If you look at other libraries, that is the most common approach and offers the best way to compose multiple plot calls onto a given axes or set of axes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes a lot of sense to me. I did it this way partly because the existing software does a few extra things, like renaming the figure "root locus". And it instead names it "root locus 1", "root locus 2" etc if there are pre-existing "root locus" plots. I was hesitant to break that functionality.

My natural inclination would be to take that part out because it is complex, inflexible, and not in keeping with the conventions elsewhere in the library and, like you say, on plotting routines in general (e.g. pzmap re-uses current axes), but I didn't want to step on any toes.

Choose a reason for hiding this comment

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

It may be ok to remove that figure name. It isn't a strong backwards compatibility break.

But you can access the figure an axis attached to with:

In [7]: import matplotlib.pyplot as plt                                                                  

In [8]: fig, ax = plt.subplots()                                                                         


In [10]: ax.figure                                                                                       
Out[10]: <Figure size 640x480 with 1 Axes>

In [11]: ax.figure == fig                                                                                
Out[11]: True

So you can append or replace the title in the figure. This should probably have an option for it too though, i.e. modify_figure_name=True.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Jason, that was super helpful, I used it to make some changes.

  • Updated the PR to make it plot in the current axis instead of the current figure.
  • removed deprecated pylab import in favor of matplotlib
  • And OK, I took out the figure (re-)naming code. Instead it now just adds a title to the plot axes.
  • Incidentally, this seems like it may have fixed the slow zooming problem referenced on lines 180-181. (at least it did for me)

@moorepants
Copy link

I'm good with this change, but one of the lead devs will have to comment and approve.

@murrayrm
Copy link
Member

Everywhere else in python-control we import matplotlib as mpl rather than mlt, so I made that change here as well. Otherwise looks good and I will merge in a bit (assuming Travis passes).

@murrayrm murrayrm merged commit bdf81b1 into python-control:master Jul 11, 2020
@sawyerbfuller sawyerbfuller deleted the rlocus-no-new-figure branch July 15, 2020 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants