@@ -1639,8 +1639,11 @@ def set_params(self, **kwargs):
1639
1639
1640
1640
def _raw_ticks (self , vmin , vmax ):
1641
1641
if self ._nbins == 'auto' :
1642
- nbins = max (min (self .axis .get_tick_space (), 9 ),
1643
- max (1 , self ._min_n_ticks - 1 ))
1642
+ if self .axis is not None :
1643
+ nbins = max (min (self .axis .get_tick_space (), 9 ),
1644
+ max (1 , self ._min_n_ticks - 1 ))
1645
+ else :
1646
+ nbins = 9
1644
1647
else :
1645
1648
nbins = self ._nbins
1646
1649
@@ -1757,15 +1760,19 @@ class LogLocator(Locator):
1757
1760
Determine the tick locations for log axes
1758
1761
"""
1759
1762
1760
- def __init__ (self , base = 10.0 , subs = (1.0 ,), numdecs = 4 , numticks = 15 ):
1763
+ def __init__ (self , base = 10.0 , subs = (1.0 ,), numdecs = 4 , numticks = None ):
1761
1764
"""
1762
1765
place ticks on the location= base**i*subs[j]
1763
1766
"""
1767
+ if numticks is None :
1768
+ if rcParams ['_internal.classic_mode' ]:
1769
+ numticks = 15
1770
+ else :
1771
+ numticks = 'auto'
1764
1772
self .base (base )
1765
1773
self .subs (subs )
1766
- # this needs to be validated > 1 with traitlets
1767
- self .numticks = numticks
1768
1774
self .numdecs = numdecs
1775
+ self .numticks = numticks
1769
1776
1770
1777
def set_params (self , base = None , subs = None , numdecs = None , numticks = None ):
1771
1778
"""Set parameters within this locator."""
@@ -1786,7 +1793,7 @@ def base(self, base):
1786
1793
1787
1794
def subs (self , subs ):
1788
1795
"""
1789
- set the minor ticks the log scaling every base**i*subs[j]
1796
+ set the minor ticks for the log scaling every base**i*subs[j]
1790
1797
"""
1791
1798
if subs is None :
1792
1799
self ._subs = None # autosub
@@ -1799,6 +1806,14 @@ def __call__(self):
1799
1806
return self .tick_values (vmin , vmax )
1800
1807
1801
1808
def tick_values (self , vmin , vmax ):
1809
+ if self .numticks == 'auto' :
1810
+ if self .axis is not None :
1811
+ numticks = max (min (self .axis .get_tick_space (), 9 ), 2 )
1812
+ else :
1813
+ numticks = 9
1814
+ else :
1815
+ numticks = self .numticks
1816
+
1802
1817
b = self ._base
1803
1818
# dummy axis has no axes attribute
1804
1819
if hasattr (self .axis , 'axes' ) and self .axis .axes .name == 'polar' :
@@ -1836,12 +1851,14 @@ def tick_values(self, vmin, vmax):
1836
1851
subs = self ._subs
1837
1852
1838
1853
stride = 1
1839
- if not self .numticks > 1 :
1840
- raise RuntimeError ('The number of ticks must be greater than 1 '
1841
- 'for LogLocator.' )
1842
- # FIXME: The following was designed for integer division in py2.
1843
- while numdec / stride + 1 > self .numticks :
1844
- stride += 1
1854
+
1855
+ if rcParams ['_internal.classic_mode' ]:
1856
+ # Leave the bug left over from the PY2-PY3 transition.
1857
+ while numdec / stride + 1 > numticks :
1858
+ stride += 1
1859
+ else :
1860
+ while numdec // stride + 1 > numticks :
1861
+ stride += 1
1845
1862
1846
1863
decades = np .arange (math .floor (vmin ) - stride ,
1847
1864
math .ceil (vmax ) + 2 * stride , stride )
0 commit comments