@@ -1639,8 +1639,11 @@ def set_params(self, **kwargs):
16391639
16401640 def _raw_ticks (self , vmin , vmax ):
16411641 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
16441647 else :
16451648 nbins = self ._nbins
16461649
@@ -1757,15 +1760,19 @@ class LogLocator(Locator):
17571760 Determine the tick locations for log axes
17581761 """
17591762
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 ):
17611764 """
17621765 place ticks on the location= base**i*subs[j]
17631766 """
1767+ if numticks is None :
1768+ if rcParams ['_internal.classic_mode' ]:
1769+ numticks = 15
1770+ else :
1771+ numticks = 'auto'
17641772 self .base (base )
17651773 self .subs (subs )
1766- # this needs to be validated > 1 with traitlets
1767- self .numticks = numticks
17681774 self .numdecs = numdecs
1775+ self .numticks = numticks
17691776
17701777 def set_params (self , base = None , subs = None , numdecs = None , numticks = None ):
17711778 """Set parameters within this locator."""
@@ -1786,7 +1793,7 @@ def base(self, base):
17861793
17871794 def subs (self , subs ):
17881795 """
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]
17901797 """
17911798 if subs is None :
17921799 self ._subs = None # autosub
@@ -1799,6 +1806,14 @@ def __call__(self):
17991806 return self .tick_values (vmin , vmax )
18001807
18011808 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+
18021817 b = self ._base
18031818 # dummy axis has no axes attribute
18041819 if hasattr (self .axis , 'axes' ) and self .axis .axes .name == 'polar' :
@@ -1836,12 +1851,14 @@ def tick_values(self, vmin, vmax):
18361851 subs = self ._subs
18371852
18381853 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
18451862
18461863 decades = np .arange (math .floor (vmin ) - stride ,
18471864 math .ceil (vmax ) + 2 * stride , stride )
0 commit comments