@@ -723,6 +723,8 @@ def __init__(self, axes, pickradius=15):
723
723
`.Axis.contains`.
724
724
"""
725
725
martist .Artist .__init__ (self )
726
+ self ._remove_overlapping_locs = True
727
+
726
728
self .set_figure (axes .figure )
727
729
728
730
self .isDefault_label = True
@@ -754,6 +756,17 @@ def __init__(self, axes, pickradius=15):
754
756
majorTicks = _LazyTickList (major = True )
755
757
minorTicks = _LazyTickList (major = False )
756
758
759
+ def get_remove_overlapping_locs (self ):
760
+ return self ._remove_overlapping_locs
761
+
762
+ def set_remove_overlapping_locs (self , val ):
763
+ self ._remove_overlapping_locs = bool (val )
764
+
765
+ remove_overlapping_locs = property (
766
+ get_remove_overlapping_locs , set_remove_overlapping_locs ,
767
+ doc = ('If minor ticker locations that overlap with major '
768
+ 'ticker locations should be trimmed.' ))
769
+
757
770
def set_label_coords (self , x , y , transform = None ):
758
771
"""
759
772
Set the coordinates of the label.
@@ -1064,23 +1077,29 @@ def _update_ticks(self):
1064
1077
Update ticks (position and labels) using the current data interval of
1065
1078
the axes. Return the list of ticks that will be drawn.
1066
1079
"""
1067
-
1068
- major_locs = self .major .locator ()
1069
- major_ticks = self .get_major_ticks (len (major_locs ))
1080
+ major_locs = self .get_majorticklocs ()
1070
1081
major_labels = self .major .formatter .format_ticks (major_locs )
1082
+ major_ticks = self .get_major_ticks (len (major_locs ))
1083
+ self .major .formatter .set_locs (major_locs )
1071
1084
for tick , loc , label in zip (major_ticks , major_locs , major_labels ):
1072
1085
tick .update_position (loc )
1073
1086
tick .set_label1 (label )
1074
1087
tick .set_label2 (label )
1075
- minor_locs = self .minor .locator ()
1076
- minor_ticks = self .get_minor_ticks (len (minor_locs ))
1088
+ minor_locs = self .get_minorticklocs ()
1077
1089
minor_labels = self .minor .formatter .format_ticks (minor_locs )
1090
+ minor_ticks = self .get_minor_ticks (len (minor_locs ))
1091
+ self .minor .formatter .set_locs (minor_locs )
1078
1092
for tick , loc , label in zip (minor_ticks , minor_locs , minor_labels ):
1079
1093
tick .update_position (loc )
1080
1094
tick .set_label1 (label )
1081
1095
tick .set_label2 (label )
1082
1096
ticks = [* major_ticks , * minor_ticks ]
1083
1097
1098
+ # mark the ticks that we will not be using as not visible
1099
+ for t in (self .minorTicks [len (minor_locs ):] +
1100
+ self .majorTicks [len (major_locs ):]):
1101
+ t .set_visible (False )
1102
+
1084
1103
view_low , view_high = self .get_view_interval ()
1085
1104
if view_low > view_high :
1086
1105
view_low , view_high = view_high , view_low
@@ -1322,9 +1341,10 @@ def get_minorticklocs(self):
1322
1341
# Use the transformed view limits as scale. 1e-5 is the default rtol
1323
1342
# for np.isclose.
1324
1343
tol = (hi - lo ) * 1e-5
1325
- minor_locs = [
1326
- loc for loc , tr_loc in zip (minor_locs , tr_minor_locs )
1327
- if not np .isclose (tr_loc , tr_major_locs , atol = tol , rtol = 0 ).any ()]
1344
+ if self .remove_overlapping_locs :
1345
+ minor_locs = [
1346
+ loc for loc , tr_loc in zip (minor_locs , tr_minor_locs )
1347
+ if ~ np .isclose (tr_loc , tr_major_locs , atol = tol , rtol = 0 ).any ()]
1328
1348
return minor_locs
1329
1349
1330
1350
def get_ticklocs (self , minor = False ):
@@ -1390,7 +1410,7 @@ def get_minor_formatter(self):
1390
1410
def get_major_ticks (self , numticks = None ):
1391
1411
'Get the tick instances; grow as necessary.'
1392
1412
if numticks is None :
1393
- numticks = len (self .get_major_locator () ())
1413
+ numticks = len (self .get_majorticklocs ())
1394
1414
1395
1415
while len (self .majorTicks ) < numticks :
1396
1416
# Update the new tick label properties from the old.
@@ -1404,7 +1424,7 @@ def get_major_ticks(self, numticks=None):
1404
1424
def get_minor_ticks (self , numticks = None ):
1405
1425
'Get the minor tick instances; grow as necessary.'
1406
1426
if numticks is None :
1407
- numticks = len (self .get_minor_locator () ())
1427
+ numticks = len (self .get_minorticklocs ())
1408
1428
1409
1429
while len (self .minorTicks ) < numticks :
1410
1430
# Update the new tick label properties from the old.
0 commit comments