7171
7272# Main function: compute a root locus diagram
7373def root_locus (sys , kvect = None , xlim = None , ylim = None ,
74- plotstr = None , plot = True , print_gain = None , grid = None , ** kwargs ):
74+ plotstr = None , plot = True , print_gain = None , grid = None , fig = None ,
75+ ** kwargs ):
7576
7677 """Root locus plot
7778
@@ -96,6 +97,8 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None,
9697 branches, calculate gain, damping and print.
9798 grid : bool
9899 If True plot omega-damping grid. Default is False.
100+ fig : Matplotlib figure
101+ Figure in which to create root locus plot
99102
100103 Returns
101104 -------
@@ -143,10 +146,11 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None,
143146 # Create the Plot
144147 if plot :
145148 if sisotool :
146- f = kwargs ['fig' ]
147- ax = f .axes [1 ]
149+ ax = fig .axes [1 ]
148150
149151 else :
152+ if fig is None :
153+ fig = pylab .gcf ()
150154 figure_number = pylab .get_fignums ()
151155 figure_title = [
152156 pylab .figure (numb ).canvas .get_window_title ()
@@ -156,29 +160,29 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None,
156160 while new_figure_name in figure_title :
157161 new_figure_name = "Root Locus " + str (rloc_num )
158162 rloc_num += 1
159- f = pylab . figure (new_figure_name )
163+ fig . canvas . set_window_title (new_figure_name )
160164 ax = pylab .axes ()
161165
162166 if print_gain and not sisotool :
163- f .canvas .mpl_connect (
167+ fig .canvas .mpl_connect (
164168 'button_release_event' ,
165- partial (_RLClickDispatcher , sys = sys , fig = f ,
166- ax_rlocus = f .axes [0 ], plotstr = plotstr ))
169+ partial (_RLClickDispatcher , sys = sys , fig = fig ,
170+ ax_rlocus = fig .axes [0 ], plotstr = plotstr ))
167171
168172 elif sisotool :
169- f .axes [1 ].plot (
173+ fig .axes [1 ].plot (
170174 [root .real for root in start_mat ],
171175 [root .imag for root in start_mat ],
172176 'm.' , marker = 's' , markersize = 8 , zorder = 20 , label = 'gain_point' )
173- f .suptitle (
177+ fig .suptitle (
174178 "Clicked at: %10.4g%+10.4gj gain: %10.4g damp: %10.4g" %
175179 (start_mat [0 ][0 ].real , start_mat [0 ][0 ].imag ,
176180 1 , - 1 * start_mat [0 ][0 ].real / abs (start_mat [0 ][0 ])),
177181 fontsize = 12 if int (matplotlib .__version__ [0 ]) == 1 else 10 )
178- f .canvas .mpl_connect (
182+ fig .canvas .mpl_connect (
179183 'button_release_event' ,
180- partial (_RLClickDispatcher , sys = sys , fig = f ,
181- ax_rlocus = f .axes [1 ], plotstr = plotstr ,
184+ partial (_RLClickDispatcher , sys = sys , fig = fig ,
185+ ax_rlocus = fig .axes [1 ], plotstr = plotstr ,
182186 sisotool = sisotool ,
183187 bode_plot_params = kwargs ['bode_plot_params' ],
184188 tvect = kwargs ['tvect' ]))
0 commit comments