Title: Reimplementation of 2D phase plots by murrayrm · Pull Request #980 · python-control/python-control · GitHub
Open Graph Title: Reimplementation of 2D phase plots by murrayrm · Pull Request #980 · python-control/python-control
X Title: Reimplementation of 2D phase plots by murrayrm · Pull Request #980 · python-control/python-control
Description: This PR reimplements the phase plot functionality of python-control by creating a new function phase_plane_plot and creating a module phaseplot that provides more specialized functionality. The legacy phase_plot function is still available (with a deprecation warning). From the documentation: The default method for generating a phase plane plot is to provide a 2D dynamical system along with a range of coordinates and time limit: sys = ct.nlsys( lambda t, x, u, params: np.array([[0, 1], [-1, -1]]) @ x, states=['position', 'velocity'], inputs=0, name='damped oscillator') axis_limits = [-1, 1, -1, 1] T = 8 ct.phase_plane_plot(sys, axis_limits, T) By default, the plot includes streamlines generated from starting points on limits of the plot, with arrows showing the flow of the system, as well as any equilibrium points for the system. A variety of options are available to modify the information that is plotted, including plotting a grid of vectors instead of streamlines and turning on and off various features of the plot. To illustrate some of these possibilities, consider a phase plane plot for an inverted pendulum system, which is created using a mesh grid: def invpend_update(t, x, u, params): m, l, b, g = params['m'], params['l'], params['b'], params['g'] return [x[1], -b/m * x[1] + (g * l / m) * np.sin(x[0]) + u[0]/m] invpend = ct.nlsys(invpend_update, states=2, inputs=1, name='invpend') ct.phase_plane_plot( invpend, [-2*pi, 2*pi, -2, 2], 5, gridtype='meshgrid', gridspec=[5, 8], arrows=3, plot_equilpoints={'gridspec': [12, 9]}, params={'m': 1, 'l': 1, 'b': 0.2, 'g': 1}) plt.xlabel(r"$\theta$ [rad]") plt.ylabel(r"$\dot\theta$ [rad/sec]") This figure shows several features of more complex phase plane plots: multiple equilibrium points are shown, with saddle points showing separatrices, and streamlines generated along a 5x8 mesh of initial conditions. At each mesh point, a streamline is created that goes 5 time units forward and backward in time. A separate grid specification is used to find equilibrium points and separatrices (since the course grid spacing of 5x8 does not find all possible equilibrium points). Together, the multiple features in the phase plane plot give a good global picture of the topological strucrure of solutions of the dynamical system. Phase plots can be buit up by hand using a variety of helper functions that are part of the control.phaseplot (pp) module: import control.phaseplot as pp def oscillator_update(t, x, u, params): return [x[1] + x[0] * (1 - x[0]**2 - x[1]**2), -x[0] + x[1] * (1 - x[0]**2 - x[1]**2)] oscillator = ct.nlsys( oscillator_update, states=2, inputs=0, name='nonlinear oscillator') ct.phase_plane_plot(oscillator, [-1.5, 1.5, -1.5, 1.5], 0.9) pp.streamlines( oscillator, np.array([[0, 0]]), 1.5, gridtype='circlegrid', gridspec=[0.5, 6], dir='both') pp.streamlines( oscillator, np.array([[1, 0]]), 2*pi, arrows=6, color='b') plt.gca().set_aspect('equal') The following helper functions are available: pp.equilpoints pp.separatrices pp.streamlines pp.vectorfield The phase_plane_plot function calls these helper functions based on the options it is passed. Note that unlike other plotting function, phase plane plots do not involve computing a response and then plotting the result via a plot() method. Instead, the plot is generated directly be a call to the phase_plane_plot function (or one of the ct.phaseplot helper functions.
Open Graph Description: This PR reimplements the phase plot functionality of python-control by creating a new function phase_plane_plot and creating a module phaseplot that provides more specialized functionality. The le...
X Description: This PR reimplements the phase plot functionality of python-control by creating a new function phase_plane_plot and creating a module phaseplot that provides more specialized functionality. The le...
Opengraph URL: https://github.com/python-control/python-control/pull/980
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:bcb9c8c4-70f2-5925-d0b5-ba4bbc39aa3f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D41E:D4CEC:1DD4F4:28F360:697BBAB5 |
| html-safe-nonce | fe60f8ca65033f9b7c1d0449f460eeb8eddf70695828970f4d48c24be58d187a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDFFOkQ0Q0VDOjFERDRGNDoyOEYzNjA6Njk3QkJBQjUiLCJ2aXNpdG9yX2lkIjoiODc1NzYzNDE3NzQxMjM0ODU5NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1fd79ede829e78500aa94879988cf0eb974177063bfb10ba7936be134bec108d |
| hovercard-subject-tag | pull_request:1795145666 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-control/python-control/pull/980/files |
| twitter:image | https://avatars.githubusercontent.com/u/293362?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/293362?s=400&v=4 |
| og:image:alt | This PR reimplements the phase plot functionality of python-control by creating a new function phase_plane_plot and creating a module phaseplot that provides more specialized functionality. The le... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ab413746e1b95376981dfec4a04b2384a611b96affe802ee3ee6d752200afbb1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-control/python-control git https://github.com/python-control/python-control.git |
| octolytics-dimension-user_id | 2285872 |
| octolytics-dimension-user_login | python-control |
| octolytics-dimension-repository_id | 22791752 |
| octolytics-dimension-repository_nwo | python-control/python-control |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 22791752 |
| octolytics-dimension-repository_network_root_nwo | python-control/python-control |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bea0e0f1995ab0bb7fa336572c353032cf897ec1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width