diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 162b364bdbe5..a2c71ecdaad6 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -235,6 +235,12 @@ def validate_int_or_None(s): raise ValueError('Could not convert "%s" to int' % s) +def validate_int_or_auto(s): + if s == 'auto': + return s + return validate_int(s) + + def validate_fonttype(s): """ confirm that this is a Postscript of PDF font type that we know how to @@ -1310,10 +1316,11 @@ def _validate_linestyle(ls): 'xtick.minor.bottom': [True, validate_bool], # draw x axis bottom minor ticks 'xtick.major.top': [True, validate_bool], # draw x axis top major ticks 'xtick.major.bottom': [True, validate_bool], # draw x axis bottom major ticks + 'xtick.minor.ndivs': ['auto', validate_int_or_auto], # sets ndivs value for x axis minor ticks # fontsize of the xtick labels 'xtick.labelsize': ['medium', validate_fontsize], - 'xtick.direction': ['out', validate_string], # direction of xticks + 'xtick.direction': ['out', validate_string], # direction of xticks 'xtick.alignment': ["center", _validate_alignment], 'ytick.left': [True, validate_bool], # draw ticks on the left side @@ -1332,10 +1339,11 @@ def _validate_linestyle(ls): 'ytick.minor.right': [True, validate_bool], # draw y axis right minor ticks 'ytick.major.left': [True, validate_bool], # draw y axis left major ticks 'ytick.major.right': [True, validate_bool], # draw y axis right major ticks + 'ytick.minor.ndivs': ['auto', validate_int_or_auto], # sets ndivs value for y axis minor ticks # fontsize of the ytick labels 'ytick.labelsize': ['medium', validate_fontsize], - 'ytick.direction': ['out', validate_string], # direction of yticks + 'ytick.direction': ['out', validate_string], # direction of yticks 'ytick.alignment': ["center_baseline", _validate_alignment], 'grid.color': ['#b0b0b0', validate_color], # grid color diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 337cda1a84f4..985933b79681 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2638,6 +2638,12 @@ def __init__(self, n=None): def __call__(self): 'Return the locations of the ticks' + if self.ndivs is None: + if self.axis.__name__ == 'xaxis': + self.ndivs = rcParams['xtick.minor.ndivs'] + elif self.axis.__name__ == 'yaxis': + self.ndivs = rcParams['ytick.minor.ndivs'] + if self.axis.get_scale() == 'log': cbook._warn_external('AutoMinorLocator does not work with ' 'logarithmic scale') @@ -2653,7 +2659,7 @@ def __call__(self): # no ticks at all. return [] - if self.ndivs is None: + if self.ndivs == 'auto': majorstep_no_exponent = 10 ** (np.log10(majorstep) % 1) diff --git a/matplotlibrc.template b/matplotlibrc.template index cf1e810af740..a5dd93176ce6 100644 --- a/matplotlibrc.template +++ b/matplotlibrc.template @@ -377,6 +377,7 @@ #xtick.minor.top : True ## draw x axis top minor ticks #xtick.minor.bottom : True ## draw x axis bottom minor ticks #xtick.alignment : center ## alignment of xticks +#xtick.minor.ndivs : auto ## set ndivs value for x axis minor ticks #ytick.left : True ## draw ticks on the left side #ytick.right : False ## draw ticks on the right side @@ -397,6 +398,7 @@ #ytick.minor.left : True ## draw y axis left minor ticks #ytick.minor.right : True ## draw y axis right minor ticks #ytick.alignment : center_baseline ## alignment of yticks +#ytick.minor.ndivs : auto ## set ndivs value for y axis minor ticks #### GRIDS #grid.color : b0b0b0 ## grid color