@@ -646,8 +646,9 @@ def _sgrid_func(fig=None, zeta=None, wn=None):
646
646
else :
647
647
ax = fig .axes [1 ]
648
648
649
- # Get locator function for x-axis tick marks
649
+ # Get locator function for x-axis, y-axis tick marks
650
650
xlocator = ax .get_xaxis ().get_major_locator ()
651
+ ylocator = ax .get_yaxis ().get_major_locator ()
651
652
652
653
# Decide on the location for the labels (?)
653
654
ylim = ax .get_ylim ()
@@ -690,7 +691,7 @@ def _sgrid_func(fig=None, zeta=None, wn=None):
690
691
# omega-constant lines
691
692
angles = np .linspace (- 90 , 90 , 20 ) * np .pi / 180
692
693
if wn is None :
693
- wn = _default_wn (xlocator (), ylim )
694
+ wn = _default_wn (xlocator (), ylocator () )
694
695
695
696
for om in wn :
696
697
if om < 0 :
@@ -746,7 +747,7 @@ def _default_zetas(xlim, ylim):
746
747
return zeta .tolist ()
747
748
748
749
749
- def _default_wn (xloc , ylim ):
750
+ def _default_wn (xloc , yloc , max_lines = 7 ):
750
751
"""Return default wn for root locus plot
751
752
752
753
This function computes a list of natural frequencies based on the grid
@@ -758,23 +759,30 @@ def _default_wn(xloc, ylim):
758
759
List of x-axis tick values
759
760
ylim : array_like
760
761
List of y-axis limits [min, max]
762
+ max_lines : int, optional
763
+ Maximum number of frequencies to generate (default = 7)
761
764
762
765
Returns
763
766
-------
764
767
wn : list
765
768
List of default natural frequencies for the plot
766
769
767
770
"""
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
768
779
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 )
775
783
776
784
# If there are too many values, cut them in half
777
- while len (wn ) > 7 :
785
+ while len (wn ) > max_lines :
778
786
wn = wn [0 :- 1 :2 ]
779
787
780
788
return wn
0 commit comments