@@ -646,8 +646,9 @@ def _sgrid_func(fig=None, zeta=None, wn=None):
646646 else :
647647 ax = fig .axes [1 ]
648648
649- # Get locator function for x-axis tick marks
649+ # Get locator function for x-axis, y-axis tick marks
650650 xlocator = ax .get_xaxis ().get_major_locator ()
651+ ylocator = ax .get_yaxis ().get_major_locator ()
651652
652653 # Decide on the location for the labels (?)
653654 ylim = ax .get_ylim ()
@@ -690,7 +691,7 @@ def _sgrid_func(fig=None, zeta=None, wn=None):
690691 # omega-constant lines
691692 angles = np .linspace (- 90 , 90 , 20 ) * np .pi / 180
692693 if wn is None :
693- wn = _default_wn (xlocator (), ylim )
694+ wn = _default_wn (xlocator (), ylocator () )
694695
695696 for om in wn :
696697 if om < 0 :
@@ -746,7 +747,7 @@ def _default_zetas(xlim, ylim):
746747 return zeta .tolist ()
747748
748749
749- def _default_wn (xloc , ylim ):
750+ def _default_wn (xloc , yloc , max_lines = 7 ):
750751 """Return default wn for root locus plot
751752
752753 This function computes a list of natural frequencies based on the grid
@@ -758,23 +759,30 @@ def _default_wn(xloc, ylim):
758759 List of x-axis tick values
759760 ylim : array_like
760761 List of y-axis limits [min, max]
762+ max_lines : int, optional
763+ Maximum number of frequencies to generate (default = 7)
761764
762765 Returns
763766 -------
764767 wn : list
765768 List of default natural frequencies for the plot
766769
767770 """
771+ sep = xloc [1 ]- xloc [0 ] # separation between x-ticks
772+
773+ # Decide whether to use the x or y axis for determining wn
774+ if yloc [- 1 ] / sep > max_lines * 10 :
775+ # y-axis scale >> x-axis scale
776+ wn = yloc # one frequency per y-axis tick mark
777+ else :
778+ wn = xloc # one frequency per x-axis tick mark
768779
769- wn = xloc # one frequency per x-axis tick mark
770- sep = xloc [1 ]- xloc [0 ] # separation between ticks
771-
772- # Insert additional frequencies to span the y-axis
773- while np .abs (wn [0 ]) < ylim [1 ]:
774- wn = np .insert (wn , 0 , wn [0 ]- sep )
780+ # Insert additional frequencies to span the y-axis
781+ while np .abs (wn [0 ]) < yloc [- 1 ]:
782+ wn = np .insert (wn , 0 , wn [0 ]- sep )
775783
776784 # If there are too many values, cut them in half
777- while len (wn ) > 7 :
785+ while len (wn ) > max_lines :
778786 wn = wn [0 :- 1 :2 ]
779787
780788 return wn
0 commit comments