@@ -925,7 +925,11 @@ def minorticksubplot(xminor, yminor, i):
925
925
minorticksubplot (True , True , 4 )
926
926
927
927
928
- def test_remove_overlap ():
928
+ @pytest .mark .parametrize ('remove_overlapping_locs, expected_num' ,
929
+ ((True , 6 ),
930
+ (None , 6 ), # this tests the default
931
+ (False , 9 )))
932
+ def test_remove_overlap (remove_overlapping_locs , expected_num ):
929
933
import numpy as np
930
934
import matplotlib .dates as mdates
931
935
@@ -940,7 +944,28 @@ def test_remove_overlap():
940
944
941
945
ax .xaxis .set_minor_locator (mdates .HourLocator ((0 , 6 , 12 , 18 )))
942
946
ax .xaxis .set_minor_formatter (mdates .DateFormatter ('%H:%M' ))
943
-
944
- assert len (ax .xaxis .get_minorticklocs ()) == 6
945
- ax .xaxis .remove_overlapping_locs = False
946
- assert len (ax .xaxis .get_minorticklocs ()) == 9
947
+ # force there to be extra ticks
948
+ ax .xaxis .get_minor_ticks (15 )
949
+ if remove_overlapping_locs is not None :
950
+ ax .xaxis .remove_overlapping_locs = remove_overlapping_locs
951
+
952
+ # check that getter/setter exists
953
+ current = ax .xaxis .remove_overlapping_locs
954
+ assert (current == ax .xaxis .get_remove_overlapping_locs ())
955
+ plt .setp (ax .xaxis , remove_overlapping_locs = current )
956
+ new = ax .xaxis .remove_overlapping_locs
957
+ assert (new == ax .xaxis .remove_overlapping_locs )
958
+
959
+ # check that the accessors filter correctly
960
+ # this is the method that does the actual filtering
961
+ assert len (ax .xaxis .get_minorticklocs ()) == expected_num
962
+ # these three are derivative
963
+ assert len (ax .xaxis .get_minor_ticks ()) == expected_num
964
+ assert len (ax .xaxis .get_minorticklabels ()) == expected_num
965
+ assert len (ax .xaxis .get_minorticklines ()) == expected_num * 2
966
+
967
+ # force a draw to call _update_ticks under the hood
968
+ fig .canvas .draw ()
969
+ # check that the correct number of ticks report them selves as
970
+ # visible
971
+ assert sum (t .get_visible () for t in ax .xaxis .minorTicks ) == expected_num
0 commit comments