1515import control as ct
1616import control .phaseplot as pp
1717
18+ # Set default plotting parameters to match ControlPlot
19+ plt .rcParams .update (ct .rcParams )
20+
1821#
1922# Example 1: Dampled oscillator systems
2023#
@@ -32,17 +35,17 @@ def damposc_update(t, x, u, params):
3235fig .set_tight_layout (True )
3336plt .suptitle ("FBS Figure 5.3: damped oscillator" )
3437
35- ct .phase_plane_plot (damposc , [- 1 , 1 , - 1 , 1 ], 8 , ax = ax1 , plot_streamlines = True )
38+ ct .phase_plane_plot (damposc , [- 1 , 1 , - 1 , 1 ], 8 , ax = ax1 )
3639ax1 .set_title ("boxgrid [-1, 1, -1, 1], 8" )
3740
3841ct .phase_plane_plot (damposc , [- 1 , 1 , - 1 , 1 ], ax = ax2 , plot_streamlines = True ,
3942 gridtype = 'meshgrid' )
40- ax2 .set_title ("meshgrid [-1, 1, -1, 1]" )
43+ ax2 .set_title ("streamlines, meshgrid [-1, 1, -1, 1]" )
4144
4245ct .phase_plane_plot (
4346 damposc , [- 1 , 1 , - 1 , 1 ], 4 , ax = ax3 , plot_streamlines = True ,
4447 gridtype = 'circlegrid' , dir = 'both' )
45- ax3 .set_title ("circlegrid [0, 0, 1], 4, both" )
48+ ax3 .set_title ("streamlines, circlegrid [0, 0, 1], 4, both" )
4649
4750ct .phase_plane_plot (
4851 damposc , [- 1 , 1 , - 1 , 1 ], ax = ax4 , gridtype = 'circlegrid' ,
@@ -65,18 +68,18 @@ def invpend_update(t, x, u, params):
6568plt .suptitle ("FBS Figure 5.4: inverted pendulum" )
6669
6770ct .phase_plane_plot (
68- invpend , [- 2 * pi , 2 * pi , - 2 , 2 ], 5 , ax = ax1 , plot_streamlines = True )
71+ invpend , [- 2 * pi , 2 * pi , - 2 , 2 ], 5 , ax = ax1 )
6972ax1 .set_title ("default, 5" )
7073
7174ct .phase_plane_plot (
7275 invpend , [- 2 * pi , 2 * pi , - 2 , 2 ], gridtype = 'meshgrid' , ax = ax2 ,
7376 plot_streamlines = True )
74- ax2 .set_title ("meshgrid" )
77+ ax2 .set_title ("streamlines, meshgrid" )
7578
7679ct .phase_plane_plot (
7780 invpend , [- 2 * pi , 2 * pi , - 2 , 2 ], 1 , gridtype = 'meshgrid' ,
7881 gridspec = [12 , 9 ], ax = ax3 , arrows = 1 , plot_streamlines = True )
79- ax3 .set_title ("denser grid" )
82+ ax3 .set_title ("streamlines, denser grid" )
8083
8184ct .phase_plane_plot (
8285 invpend , [- 2 * pi , 2 * pi , - 2 , 2 ], 4 , gridspec = [6 , 6 ],
@@ -99,8 +102,7 @@ def oscillator_update(t, x, u, params):
99102fig .set_tight_layout (True )
100103plt .suptitle ("FBS Figure 5.5: Nonlinear oscillator" )
101104
102- ct .phase_plane_plot (oscillator , [- 1.5 , 1.5 , - 1.5 , 1.5 ], 3 , ax = ax1 ,
103- plot_streamlines = True )
105+ ct .phase_plane_plot (oscillator , [- 1.5 , 1.5 , - 1.5 , 1.5 ], 3 , ax = ax1 )
104106ax1 .set_title ("default, 3" )
105107ax1 .set_aspect ('equal' )
106108
@@ -111,14 +113,14 @@ def oscillator_update(t, x, u, params):
111113except RuntimeError as inst :
112114 ax2 .text (0 , 0 , "Runtime Error" )
113115 warnings .warn (inst .__str__ ())
114- ax2 .set_title ("meshgrid, forward, 0.5" )
116+ ax2 .set_title ("streamlines, meshgrid, forward, 0.5" )
115117ax2 .set_aspect ('equal' )
116118
117119ct .phase_plane_plot (oscillator , [- 1.5 , 1.5 , - 1.5 , 1.5 ], ax = ax3 ,
118120 plot_streamlines = True )
119121pp .streamlines (
120122 oscillator , [- 0.5 , 0.5 , - 0.5 , 0.5 ], dir = 'both' , ax = ax3 )
121- ax3 .set_title ("outer + inner" )
123+ ax3 .set_title ("streamlines, outer + inner" )
122124ax3 .set_aspect ('equal' )
123125
124126ct .phase_plane_plot (
@@ -143,12 +145,13 @@ def saddle_update(t, x, u, params):
143145fig .set_tight_layout (True )
144146plt .suptitle ("FBS Figure 5.9: Saddle" )
145147
146- ct .phase_plane_plot (saddle , [- 1 , 1 , - 1 , 1 ], ax = ax1 , plot_streamlines = True )
148+ ct .phase_plane_plot (saddle , [- 1 , 1 , - 1 , 1 ], ax = ax1 )
147149ax1 .set_title ("default" )
148150
149151ct .phase_plane_plot (
150- saddle , [- 1 , 1 , - 1 , 1 ], 0.5 , gridtype = 'meshgrid' , ax = ax2 , plot_streamlines = True )
151- ax2 .set_title ("meshgrid" )
152+ saddle , [- 1 , 1 , - 1 , 1 ], 0.5 , plot_streamlines = True , gridtype = 'meshgrid' ,
153+ ax = ax2 )
154+ ax2 .set_title ("streamlines, meshgrid" )
152155
153156ct .phase_plane_plot (
154157 saddle , [- 1 , 1 , - 1 , 1 ], gridspec = [16 , 12 ], ax = ax3 ,
@@ -158,7 +161,7 @@ def saddle_update(t, x, u, params):
158161ct .phase_plane_plot (
159162 saddle , [- 1 , 1 , - 1 , 1 ], 0.3 , plot_streamlines = True ,
160163 gridtype = 'meshgrid' , gridspec = [5 , 7 ], ax = ax4 )
161- ax3 .set_title ("custom" )
164+ ax4 .set_title ("custom" )
162165
163166#
164167# Example 5: Internet congestion control
@@ -178,6 +181,7 @@ def _congctrl_update(t, x, u, params):
178181 return np .append (
179182 c / x [M ] - (rho * c ) * (1 + (x [:- 1 ]** 2 ) / 2 ),
180183 N / M * np .sum (x [:- 1 ]) * c / x [M ] - c )
184+
181185congctrl = ct .nlsys (
182186 _congctrl_update , states = 2 , inputs = 0 ,
183187 params = {'N' : 60 , 'rho' : 2e-4 , 'c' : 10 })
@@ -188,15 +192,15 @@ def _congctrl_update(t, x, u, params):
188192
189193try :
190194 ct .phase_plane_plot (
191- congctrl , [0 , 10 , 100 , 500 ], 120 , ax = ax1 , plot_streamlines = True )
195+ congctrl , [0 , 10 , 100 , 500 ], 120 , ax = ax1 )
192196except RuntimeError as inst :
193197 ax1 .text (5 , 250 , "Runtime Error" )
194198 warnings .warn (inst .__str__ ())
195199ax1 .set_title ("default, T=120" )
196200
197201try :
198202 ct .phase_plane_plot (
199- congctrl , [0 , 10 , 100 , 500 ], 120 , plot_streamlines = True ,
203+ congctrl , [0 , 10 , 100 , 500 ], 120 ,
200204 params = {'rho' : 4e-4 , 'c' : 20 }, ax = ax2 )
201205except RuntimeError as inst :
202206 ax2 .text (5 , 250 , "Runtime Error" )
0 commit comments