@@ -1472,6 +1472,48 @@ def view_limits(self, dmin, dmax):
14721472 return dmin , dmax
14731473
14741474
1475+ class AutoSpacedLocator (MaxNLocator ):
1476+ """
1477+ Behaves like a MaxNLocator, except N is automatically determined
1478+ from the length of the axis.
1479+ """
1480+ def __init__ (self , * args , ** kwargs ):
1481+ """
1482+ Keyword args:
1483+
1484+ *steps*
1485+ Sequence of nice numbers starting with 1 and ending with 10;
1486+ e.g., [1, 2, 4, 5, 10]
1487+
1488+ *integer*
1489+ If True, ticks will take only integer values.
1490+
1491+ *symmetric*
1492+ If True, autoscaling will result in a range symmetric
1493+ about zero.
1494+
1495+ *prune*
1496+ ['lower' | 'upper' | 'both' | None]
1497+ Remove edge ticks -- useful for stacked or ganged plots
1498+ where the upper tick of one axes overlaps with the lower
1499+ tick of the axes above it.
1500+ If prune=='lower', the smallest tick will
1501+ be removed. If prune=='upper', the largest tick will be
1502+ removed. If prune=='both', the largest and smallest ticks
1503+ will be removed. If prune==None, no ticks will be removed.
1504+
1505+ """
1506+ if 'nbins' in kwargs :
1507+ raise ValueError (
1508+ 'AutoSpacedLocator does not take nbins as an argument' )
1509+ self .set_params (** self .default_params )
1510+ self .set_params (** kwargs )
1511+
1512+ def __call__ (self ):
1513+ self ._nbins = self .axis .get_tick_space ()
1514+ return super (AutoSpacedLocator , self ).__call__ ()
1515+
1516+
14751517def decade_down (x , base = 10 ):
14761518 'floor x to the nearest lower decade'
14771519 if x == 0.0 :
@@ -1899,9 +1941,9 @@ def tick_values(self, vmin, vmax):
18991941 return self .raise_if_exceeds (np .array (ticklocs ))
19001942
19011943
1902- class AutoLocator (MaxNLocator ):
1944+ class AutoLocator (AutoSpacedLocator ):
19031945 def __init__ (self ):
1904- MaxNLocator .__init__ (self , nbins = 9 , steps = [1 , 2 , 5 , 10 ])
1946+ AutoSpacedLocator .__init__ (self , steps = [1 , 2 , 5 , 10 ])
19051947
19061948
19071949class AutoMinorLocator (Locator ):
0 commit comments