MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / AutoMinorLocator

Class AutoMinorLocator

lib/matplotlib/ticker.py:3050–3110  ·  view source on GitHub ↗

Place evenly spaced minor ticks, with the step size and maximum number of ticks chosen automatically. The Axis must use a linear scale and have evenly spaced major ticks.

Source from the content-addressed store, hash-verified

3048
3049
3050class AutoMinorLocator(Locator):
3051 """
3052 Place evenly spaced minor ticks, with the step size and maximum number of ticks
3053 chosen automatically.
3054
3055 The Axis must use a linear scale and have evenly spaced major ticks.
3056 """
3057
3058 def __init__(self, n=None):
3059 """
3060 Parameters
3061 ----------
3062 n : int or 'auto', default: :rc:`xtick.minor.ndivs` or :rc:`ytick.minor.ndivs`
3063 The number of subdivisions of the interval between major ticks;
3064 e.g., n=2 will place a single minor tick midway between major ticks.
3065
3066 If *n* is 'auto', it will be set to 4 or 5: if the distance
3067 between the major ticks equals 1, 2.5, 5 or 10 it can be perfectly
3068 divided in 5 equidistant sub-intervals with a length multiple of
3069 0.05; otherwise, it is divided in 4 sub-intervals.
3070 """
3071 self.ndivs = n
3072
3073 def __call__(self):
3074 # docstring inherited
3075 if self.axis.get_scale() == 'log':
3076 _api.warn_external('AutoMinorLocator does not work on logarithmic scales')
3077 return []
3078
3079 majorlocs = np.unique(self.axis.get_majorticklocs())
3080 if len(majorlocs) < 2:
3081 # Need at least two major ticks to find minor tick locations.
3082 # TODO: Figure out a way to still be able to display minor ticks with less
3083 # than two major ticks visible. For now, just display no ticks at all.
3084 return []
3085 majorstep = majorlocs[1] - majorlocs[0]
3086
3087 if self.ndivs is None:
3088 self.ndivs = mpl.rcParams[
3089 'ytick.minor.ndivs' if self.axis.axis_name == 'y'
3090 else 'xtick.minor.ndivs'] # for x and z axis
3091
3092 if self.ndivs == 'auto':
3093 majorstep_mantissa = 10 ** (np.log10(majorstep) % 1)
3094 ndivs = 5 if np.isclose(majorstep_mantissa, [1, 2.5, 5, 10]).any() else 4
3095 else:
3096 ndivs = self.ndivs
3097
3098 minorstep = majorstep / ndivs
3099
3100 vmin, vmax = sorted(self.axis.get_view_interval())
3101 t0 = majorlocs[0]
3102 tmin = round((vmin - t0) / minorstep)
3103 tmax = round((vmax - t0) / minorstep) + 1
3104 locs = (np.arange(tmin, tmax) * minorstep) + t0
3105
3106 return self.raise_if_exceeds(locs)
3107

Calls

no outgoing calls

Tested by 1

test_autofmt_xdateFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…