@@ -205,11 +205,11 @@ def pole_zero_plot(
205205
206206 Returns
207207 -------
208- lines : List of Line2D
208+ lines : array of list of Line2D
209209 Array of Line2D objects for each set of markers in the plot. The
210210 shape of the array is given by (nsys, 2) where nsys is the number
211- of systems or Nyquist responses passed to the function. The second
212- index specifies the pzmap object type:
211+ of systems or responses passed to the function. The second index
212+ specifies the pzmap object type:
213213
214214 * lines[idx, 0]: poles
215215 * lines[idx, 1]: zeros
@@ -276,8 +276,11 @@ def pole_zero_plot(
276276 else :
277277 raise TypeError ("unknown system data type" )
278278
279+ # Decide whether we are plotting any root loci
280+ rlocus_plot = any ([resp .loci is not None for resp in pzmap_responses ])
281+
279282 # Turn on interactive mode by default, if allowed
280- if interactive is None and len (pzmap_responses ) == 1 \
283+ if interactive is None and rlocus_plot and len (pzmap_responses ) == 1 \
281284 and pzmap_responses [0 ].sys is not None :
282285 interactive = True
283286
@@ -318,19 +321,26 @@ def pole_zero_plot(
318321 elif all ([isdtime (dt = response .dt ) for response in data ]):
319322 ax , fig = zgrid (scaling = scaling )
320323 else :
321- ValueError (
322- "incompatible time responses; don't know how to grid" )
324+ raise ValueError (
325+ "incompatible time bases; don't know how to grid" )
326+ # Store the limits for later use
327+ xlim , ylim = ax .get_xlim (), ax .get_ylim ()
323328 elif len (axs ) == 0 :
324329 if grid == 'empty' :
325330 # Leave off grid entirely
326331 ax = plt .axes ()
332+ xlim = ylim = [0 , 0 ] # use data to set limits
327333 else :
328334 # draw stability boundary; use first response timebase
329335 ax , fig = nogrid (data [0 ].dt , scaling = scaling )
336+ xlim , ylim = ax .get_xlim (), ax .get_ylim ()
330337 else :
331338 # Use the existing axes and any grid that is there
332339 ax = axs [0 ]
333340
341+ # Store the limits for later use
342+ xlim , ylim = ax .get_xlim (), ax .get_ylim ()
343+
334344 # Issue a warning if the user tried to set the grid type
335345 if grid :
336346 warnings .warn ("axis already exists; grid keyword ignored" )
@@ -345,13 +355,12 @@ def pole_zero_plot(
345355 color_offset = color_cycle .index (last_color ) + 1
346356
347357 # Create a list of lines for the output
348- out = np .empty ((len (pzmap_responses ), 3 ), dtype = object )
358+ out = np .empty (
359+ (len (pzmap_responses ), 3 if rlocus_plot else 2 ), dtype = object )
349360 for i , j in itertools .product (range (out .shape [0 ]), range (out .shape [1 ])):
350361 out [i , j ] = [] # unique list in each element
351362
352363 # Plot the responses (and keep track of axes limits)
353- xlim , ylim = ax .get_xlim (), ax .get_ylim ()
354- loci_count = 0
355364 for idx , response in enumerate (pzmap_responses ):
356365 poles = response .poles
357366 zeros = response .zeros
@@ -397,7 +406,7 @@ def pole_zero_plot(
397406 # TODO: add arrows to root loci (reuse Nyquist arrow code?)
398407
399408 # Set the axis limits to something reasonable
400- if any ([ response . loci is not None for response in pzmap_responses ]) :
409+ if rlocus_plot :
401410 # Set up the limits for the plot using information from loci
402411 ax .set_xlim (xlim if xlim_user is None else xlim_user )
403412 ax .set_ylim (ylim if ylim_user is None else ylim_user )
0 commit comments