Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba2c9c5

Browse files
author
Aditya Sinha A
committed
Autominorticker feature added
1 parent f76508d commit ba2c9c5

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ def validate_int_or_None(s):
233233
return int(s)
234234
except ValueError:
235235
raise ValueError('Could not convert "%s" to int' % s)
236+
237+
def validate_int_or_auto(s):
238+
if s == 'auto':
239+
return s
240+
return validate_int(s)
236241

237242

238243
def validate_fonttype(s):
@@ -1310,7 +1315,7 @@ def _validate_linestyle(ls):
13101315
'xtick.minor.bottom': [True, validate_bool], # draw x axis bottom minor ticks
13111316
'xtick.major.top': [True, validate_bool], # draw x axis top major ticks
13121317
'xtick.major.bottom': [True, validate_bool], # draw x axis bottom major ticks
1313-
'xtick.minor.default': [4,validate_int], #set default value for x axis minor ticks
1318+
'xtick.minor.ndivs': ['auto', validate_int_or_auto], #set ndivs value for x axis minor ticks
13141319

13151320
# fontsize of the xtick labels
13161321
'xtick.labelsize': ['medium', validate_fontsize],
@@ -1333,7 +1338,7 @@ def _validate_linestyle(ls):
13331338
'ytick.minor.right': [True, validate_bool], # draw y axis right minor ticks
13341339
'ytick.major.left': [True, validate_bool], # draw y axis left major ticks
13351340
'ytick.major.right': [True, validate_bool], # draw y axis right major ticks
1336-
'ytick.minor.default': [4,validate_int], #set default value for y axis minor ticks
1341+
'ytick.minor.ndivs': ['auto', validate_int_or_auto], #set ndivs value for y axis minor ticks
13371342

13381343
# fontsize of the ytick labels
13391344
'ytick.labelsize': ['medium', validate_fontsize],

lib/matplotlib/ticker.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,15 @@ def __init__(self, n=None):
26342634
26352635
If *n* is omitted or None, it will be set to 5 or 4.
26362636
"""
2637-
self.ndivs = n
2637+
if n == None:
2638+
if self.axis.__name__ == 'x':
2639+
self.ndivs = rcParams['xtick.minor.ndivs']
2640+
elif self.axis.__name__ == 'y':
2641+
self.ndivs = rcParams['ytick.minor.ndivs']
2642+
elif n == 'auto':
2643+
self.ndivs = None
2644+
else:
2645+
self.ndivs = n
26382646

26392647
def __call__(self):
26402648
'Return the locations of the ticks'
@@ -2658,9 +2666,9 @@ def __call__(self):
26582666
majorstep_no_exponent = 10 ** (np.log10(majorstep) % 1)
26592667

26602668
if np.isclose(majorstep_no_exponent, [1.0, 2.5, 5.0, 10.0]).any():
2661-
ndivs = rcParams['xtick.minor.default'] + 1
2669+
ndivs = 5
26622670
else:
2663-
ndivs = rcParams['xtick.minor.default']
2671+
ndivs = 4
26642672
else:
26652673
ndivs = self.ndivs
26662674

matplotlibrc.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@
377377
#xtick.minor.top : True ## draw x axis top minor ticks
378378
#xtick.minor.bottom : True ## draw x axis bottom minor ticks
379379
#xtick.alignment : center ## alignment of xticks
380-
#xtick.minor.default : 4 ## set default value for x axis minor ticks
380+
#xtick.minor.ndivs : auto ## set ndivs value for x axis minor ticks
381381

382382
#ytick.left : True ## draw ticks on the left side
383383
#ytick.right : False ## draw ticks on the right side
@@ -398,7 +398,7 @@
398398
#ytick.minor.left : True ## draw y axis left minor ticks
399399
#ytick.minor.right : True ## draw y axis right minor ticks
400400
#ytick.alignment : center_baseline ## alignment of yticks
401-
#ytick.minor.default : 4 ## set default value for y axis minor ticks
401+
#ytick.minor.ndivs : auto ## set ndivs value for y axis minor ticks
402402

403403
#### GRIDS
404404
#grid.color : b0b0b0 ## grid color

0 commit comments

Comments
 (0)