@@ -119,13 +119,6 @@ def plot(self, *args, **kwargs):
119119 and keywords.
120120
121121 """
122- # If this is a root locus plot, use rlocus defaults for grid
123- if self .loci is not None :
124- from .rlocus import _rlocus_defaults
125- kwargs = kwargs .copy ()
126- kwargs ['grid' ] = config ._get_param (
127- 'rlocus' , 'grid' , kwargs .get ('grid' , None ), _rlocus_defaults )
128-
129122 return pole_zero_plot (self , * args , ** kwargs )
130123
131124
@@ -267,11 +260,10 @@ def pole_zero_plot(
267260
268261 """
269262 # Get parameter values
270- grid = config ._get_param ('pzmap' , 'grid' , grid , _pzmap_defaults )
271263 marker_size = config ._get_param ('pzmap' , 'marker_size' , marker_size , 6 )
272264 marker_width = config ._get_param ('pzmap' , 'marker_width' , marker_width , 1.5 )
273265 xlim_user , ylim_user = xlim , ylim
274- freqplot_rcParams = config ._get_param (
266+ rcParams = config ._get_param (
275267 'freqplot' , 'rcParams' , kwargs , _freqplot_defaults ,
276268 pop = True , last = True )
277269 user_ax = ax
@@ -315,56 +307,41 @@ def pole_zero_plot(
315307 return poles , zeros
316308
317309 # Initialize the figure
318- # TODO: turn into standard utility function (from plotutil.py?)
319- # fig, ax = _process_ax_keyword(
320- # user_ax, rcParams=freqplot_rcParams, squeeze=True, create_axes=False)
321- # axs = [ax] if ax is not None else []
322- if user_ax is None :
323- fig = plt .gcf ()
324- axs = fig .get_axes ()
325- elif isinstance (user_ax , np .ndarray ):
326- axs = user_ax .reshape (- 1 )
327- fig = axs [0 ].figure
328- else :
329- fig = ax .figure
330- axs = [ax ]
331-
332- if len (axs ) > 1 :
333- # Need to generate a new figure
334- fig , axs = plt .figure (), []
335-
336- with plt .rc_context (freqplot_rcParams ):
337- if grid and grid != 'empty' :
338- plt .clf ()
339- if all ([isctime (dt = response .dt ) for response in data ]):
340- ax , fig = sgrid (scaling = scaling )
341- elif all ([isdtime (dt = response .dt ) for response in data ]):
342- ax , fig = zgrid (scaling = scaling )
343- else :
344- raise ValueError (
345- "incompatible time bases; don't know how to grid" )
346- # Store the limits for later use
347- xlim , ylim = ax .get_xlim (), ax .get_ylim ()
348- elif len (axs ) == 0 :
349- if grid == 'empty' :
350- # Leave off grid entirely
310+ fig , ax = _process_ax_keyword (
311+ user_ax , rcParams = rcParams , squeeze = True , create_axes = False )
312+
313+ if ax is None :
314+ # Determine what type of grid to use
315+ if rlocus_plot :
316+ from .rlocus import _rlocus_defaults
317+ grid = config ._get_param ('rlocus' , 'grid' , grid , _rlocus_defaults )
318+ else :
319+ grid = config ._get_param ('pzmap' , 'grid' , grid , _pzmap_defaults )
320+
321+ # Create the axes with the appropriate grid
322+ with plt .rc_context (rcParams ):
323+ if grid and grid != 'empty' :
324+ if all ([isctime (dt = response .dt ) for response in data ]):
325+ ax , fig = sgrid (scaling = scaling )
326+ elif all ([isdtime (dt = response .dt ) for response in data ]):
327+ ax , fig = zgrid (scaling = scaling )
328+ else :
329+ raise ValueError (
330+ "incompatible time bases; don't know how to grid" )
331+ # Store the limits for later use
332+ xlim , ylim = ax .get_xlim (), ax .get_ylim ()
333+ elif grid == 'empty' :
351334 ax = plt .axes ()
352335 xlim = ylim = [np .inf , - np .inf ] # use data to set limits
353336 else :
354- # draw stability boundary; use first response timebase
355337 ax , fig = nogrid (data [0 ].dt , scaling = scaling )
356338 xlim , ylim = ax .get_xlim (), ax .get_ylim ()
357- else :
358- # Use the existing axes and any grid that is there
359- ax = axs [0 ]
360-
361- # Store the limits for later use
362- xlim , ylim = ax .get_xlim (), ax .get_ylim ()
363-
364- # Issue a warning if the user tried to set the grid type
365- if grid :
366- warnings .warn ("axis already exists; grid keyword ignored" )
367-
339+ else :
340+ # Store the limits for later use
341+ xlim , ylim = ax .get_xlim (), ax .get_ylim ()
342+ if grid is not None :
343+ warnings .warn ("axis already exists; grid keyword ignored" )
344+
368345 # Handle color cycle manually as all root locus segments
369346 # of the same system are expected to be of the same color
370347 # TODO: replace with common function?
@@ -459,13 +436,13 @@ def pole_zero_plot(
459436 handle = (pole_line , zero_line )
460437 line_tuples .append (handle )
461438
462- with plt .rc_context (freqplot_rcParams ):
439+ with plt .rc_context (rcParams ):
463440 legend = ax .legend (
464441 line_tuples , labels , loc = legend_loc ,
465442 handler_map = {tuple : HandlerTuple (ndivide = None )})
466443 else :
467444 # Regular legend, with lines
468- with plt .rc_context (freqplot_rcParams ):
445+ with plt .rc_context (rcParams ):
469446 legend = ax .legend (lines , labels , loc = legend_loc )
470447 else :
471448 legend = None
@@ -475,7 +452,8 @@ def pole_zero_plot(
475452 title = ("Root locus plot for " if rlocus_plot
476453 else "Pole/zero plot for " ) + ", " .join (labels )
477454 if user_ax is None :
478- suptitle (title )
455+ with plt .rc_context (rcParams ):
456+ fig .suptitle (title )
479457
480458 # Add dispather to handle choosing a point on the diagram
481459 if interactive :
@@ -497,7 +475,7 @@ def _click_dispatcher(event):
497475 _mark_root_locus_gain (ax , sys , K )
498476
499477 # Display the parameters in the axes title
500- with plt .rc_context (freqplot_rcParams ):
478+ with plt .rc_context (rcParams ):
501479 ax .set_title (_create_root_locus_label (sys , K , s ))
502480
503481 ax .figure .canvas .draw ()
0 commit comments