Skip to content

Add rcParams to set ndivs minor ticks on axes separately #14355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down