@@ -1734,6 +1734,46 @@ def minorticksubplot(xminor, yminor, i):
1734
1734
minorticksubplot (True , True , 4 )
1735
1735
1736
1736
1737
+ def test_minorticks_toggle ():
1738
+ """
1739
+ Test toggling minor ticks
1740
+
1741
+ Test `.Axis.minorticks_on()` and `.Axis.minorticks_off()`. Testing is
1742
+ limited to a subset of built-in scales - `'linear'`, `'log'`, `'asinh'`
1743
+ and `'logit'`. `symlog` scale does not seem to have a working minor
1744
+ locator and is omitted. In future, this test should cover all scales in
1745
+ `matplotlib.scale.get_scale_names()`.
1746
+ """
1747
+ fig = plt .figure ()
1748
+ def minortickstoggle (xminor , yminor , scale , i ):
1749
+ ax = fig .add_subplot (2 , 2 , i )
1750
+ ax .set_xscale (scale )
1751
+ ax .set_yscale (scale )
1752
+ if not xminor and not yminor :
1753
+ ax .minorticks_off ()
1754
+ if xminor and not yminor :
1755
+ ax .xaxis .minorticks_on ()
1756
+ ax .yaxis .minorticks_off ()
1757
+ if not xminor and yminor :
1758
+ ax .xaxis .minorticks_off ()
1759
+ ax .yaxis .minorticks_on ()
1760
+ if xminor and yminor :
1761
+ ax .minorticks_on ()
1762
+
1763
+ assert (len (ax .xaxis .get_minor_ticks ()) > 0 ) == xminor
1764
+ assert (len (ax .yaxis .get_minor_ticks ()) > 0 ) == yminor
1765
+
1766
+ scales = ['linear' , 'log' , 'asinh' , 'logit' ]
1767
+ for scale in scales :
1768
+ minortickstoggle (False , False , scale , 1 )
1769
+ minortickstoggle (True , False , scale , 2 )
1770
+ minortickstoggle (False , True , scale , 3 )
1771
+ minortickstoggle (True , True , scale , 4 )
1772
+ fig .clear ()
1773
+
1774
+ plt .close (fig )
1775
+
1776
+
1737
1777
@pytest .mark .parametrize ('remove_overlapping_locs, expected_num' ,
1738
1778
((True , 6 ),
1739
1779
(None , 6 ), # this tests the default
0 commit comments