5050 :class:`MaxNLocator` with simple defaults. This is the default
5151 tick locator for most plotting.
5252
53+ :class:`AutoMinorLocator`
54+ locator for minor ticks when the axis is linear and the
55+ major ticks are uniformly spaced. It subdivides the major
56+ tick interval into a specified number of minor intervals,
57+ defaulting to 4 or 5 depending on the major interval.
58+
59+
5360There are a number of locators specialized for date locations - see
5461the dates module
5562
@@ -1402,6 +1409,16 @@ class AutoMinorLocator(Locator):
14021409 major ticks. Assumes the scale is linear and major ticks are
14031410 evenly spaced.
14041411 """
1412+ def __init__ (self , n = None ):
1413+ """
1414+ *n* is the number of subdivisions of the interval between
1415+ major ticks; e.g., n=2 will place a single minor tick midway
1416+ between major ticks.
1417+
1418+ If *n* is omitted or None, it will be set to 5 or 4.
1419+ """
1420+ self .ndivs = n
1421+
14051422 def __call__ (self ):
14061423 'Return the locations of the ticks'
14071424 majorlocs = self .axis .get_majorticklocs ()
@@ -1410,25 +1427,28 @@ def __call__(self):
14101427 except IndexError :
14111428 raise ValueError ('Need at least two major ticks to find minor '
14121429 'tick locations' )
1413- # see whether major step should be divided by 5, 4. This
1414- # should cover most cases.
1415- temp = float (('%e' % majorstep ).split ('e' )[0 ])
1416- if temp % 5 < 1e-10 :
1417- minorstep = majorstep / 5.
1430+
1431+ if self .ndivs is None :
1432+ x = int (round (10 ** (np .log10 (majorstep ) % 1 )))
1433+ if x in [1 , 5 , 10 ]:
1434+ ndivs = 5
1435+ else :
1436+ ndivs = 4
14181437 else :
1419- minorstep = majorstep / 4.
1438+ ndivs = self .ndivs
1439+
1440+ minorstep = majorstep / ndivs
14201441
1421- tmin = majorlocs [0 ] - majorstep
1422- tmax = majorlocs [- 1 ] + majorstep
1423- locs = np .arange (tmin , tmax , minorstep )
14241442 vmin , vmax = self .axis .get_view_interval ()
14251443 if vmin > vmax :
14261444 vmin ,vmax = vmax ,vmin
1427- locs = locs [(vmin < locs ) & (locs < vmax )]
14281445
1429- # don't create minor ticks on top of existing major ticks
1430- diff = 0.5 * abs (locs [1 ] - locs [0 ])
1431- locs = [l for l in locs if (np .abs (l - majorlocs ) > diff ).all ()]
1446+ t0 = majorlocs [0 ]
1447+ tmin = np .ceil ((vmin - t0 ) / minorstep ) * minorstep
1448+ tmax = np .floor ((vmax - t0 ) / minorstep ) * minorstep
1449+ locs = np .arange (tmin , tmax , minorstep ) + t0
1450+ cond = np .abs ((locs - t0 ) % majorstep ) > minorstep / 10.0
1451+ locs = locs .compress (cond )
14321452
14331453 return self .raise_if_exceeds (np .array (locs ))
14341454
@@ -1495,4 +1515,4 @@ def get_locator(self, d):
14951515 'LogFormatterMathtext' , 'Locator' , 'IndexLocator' ,
14961516 'FixedLocator' , 'NullLocator' , 'LinearLocator' ,
14971517 'LogLocator' , 'AutoLocator' , 'MultipleLocator' ,
1498- 'MaxNLocator' , )
1518+ 'MaxNLocator' , 'AutoMinorLocator' , )
0 commit comments