@@ -1824,12 +1824,12 @@ class MaxNLocator(Locator):
1824
1824
"""
1825
1825
Select no more than N intervals at nice locations.
1826
1826
"""
1827
- default_params = dict (nbins = 10 ,
1828
- steps = None ,
1829
- integer = False ,
1830
- symmetric = False ,
1831
- prune = None ,
1832
- min_n_ticks = 2 )
1827
+ _default_params = dict (nbins = 10 ,
1828
+ steps = None ,
1829
+ integer = False ,
1830
+ symmetric = False ,
1831
+ prune = None ,
1832
+ min_n_ticks = 2 )
1833
1833
1834
1834
def __init__ (self , * args , ** kwargs ):
1835
1835
"""
@@ -1840,7 +1840,7 @@ def __init__(self, *args, **kwargs):
1840
1840
ticks. If the string `'auto'`, the number of bins will be
1841
1841
automatically determined based on the length of the axis.
1842
1842
1843
- steps: array-like, optional
1843
+ steps : array-like, optional
1844
1844
Sequence of nice numbers starting with 1 and ending with 10;
1845
1845
e.g., [1, 2, 4, 5, 10], where the values are acceptable
1846
1846
tick multiples. i.e. for the example, 20, 40, 60 would be
@@ -1871,12 +1871,17 @@ def __init__(self, *args, **kwargs):
1871
1871
1872
1872
"""
1873
1873
if args :
1874
+ if 'nbins' in kwargs :
1875
+ cbook .deprecated ("3.1" ,
1876
+ message = 'Calling MaxNLocator with positional '
1877
+ 'and keyword parameter *nbins* is '
1878
+ 'considered an error and will fail '
1879
+ 'in future versions of matplotlib.' )
1874
1880
kwargs ['nbins' ] = args [0 ]
1875
1881
if len (args ) > 1 :
1876
1882
raise ValueError (
1877
1883
"Keywords are required for all arguments except 'nbins'" )
1878
- self .set_params (** self .default_params )
1879
- self .set_params (** kwargs )
1884
+ self .set_params (** {** self ._default_params , ** kwargs })
1880
1885
1881
1886
@staticmethod
1882
1887
def _validate_steps (steps ):
@@ -1893,6 +1898,16 @@ def _validate_steps(steps):
1893
1898
steps = np .hstack ((steps , 10 ))
1894
1899
return steps
1895
1900
1901
+ @cbook .deprecated ("3.1" )
1902
+ @property
1903
+ def default_params (self ):
1904
+ return self ._default_params
1905
+
1906
+ @cbook .deprecated ("3.1" )
1907
+ @default_params .setter
1908
+ def default_params (self , params ):
1909
+ self ._default_params = params
1910
+
1896
1911
@staticmethod
1897
1912
def _staircase (steps ):
1898
1913
# Make an extended staircase within which the needed
@@ -1902,30 +1917,52 @@ def _staircase(steps):
1902
1917
return np .hstack (flights )
1903
1918
1904
1919
def set_params (self , ** kwargs ):
1905
- """Set parameters within this locator."""
1920
+ """
1921
+ Set parameters for this locator.
1922
+
1923
+ Parameters
1924
+ ----------
1925
+ nbins : int or 'auto', optional
1926
+ see `.MaxNLocator`
1927
+ steps : array-like, optional
1928
+ see `.MaxNLocator`
1929
+ integer : bool, optional
1930
+ see `.MaxNLocator`
1931
+ symmetric : bool, optional
1932
+ see `.MaxNLocator`
1933
+ prune : {'lower', 'upper', 'both', None}, optional
1934
+ see `.MaxNLocator`
1935
+ min_n_ticks : int, optional
1936
+ see `.MaxNLocator`
1937
+ """
1906
1938
if 'nbins' in kwargs :
1907
- self ._nbins = kwargs [ 'nbins' ]
1939
+ self ._nbins = kwargs . pop ( 'nbins' )
1908
1940
if self ._nbins != 'auto' :
1909
1941
self ._nbins = int (self ._nbins )
1910
1942
if 'symmetric' in kwargs :
1911
- self ._symmetric = kwargs [ 'symmetric' ]
1943
+ self ._symmetric = kwargs . pop ( 'symmetric' )
1912
1944
if 'prune' in kwargs :
1913
- prune = kwargs [ 'prune' ]
1945
+ prune = kwargs . pop ( 'prune' )
1914
1946
if prune is not None and prune not in ['upper' , 'lower' , 'both' ]:
1915
1947
raise ValueError (
1916
1948
"prune must be 'upper', 'lower', 'both', or None" )
1917
1949
self ._prune = prune
1918
1950
if 'min_n_ticks' in kwargs :
1919
- self ._min_n_ticks = max (1 , kwargs [ 'min_n_ticks' ] )
1951
+ self ._min_n_ticks = max (1 , kwargs . pop ( 'min_n_ticks' ) )
1920
1952
if 'steps' in kwargs :
1921
- steps = kwargs [ 'steps' ]
1953
+ steps = kwargs . pop ( 'steps' )
1922
1954
if steps is None :
1923
1955
self ._steps = np .array ([1 , 1.5 , 2 , 2.5 , 3 , 4 , 5 , 6 , 8 , 10 ])
1924
1956
else :
1925
1957
self ._steps = self ._validate_steps (steps )
1926
1958
self ._extended_steps = self ._staircase (self ._steps )
1927
1959
if 'integer' in kwargs :
1928
- self ._integer = kwargs ['integer' ]
1960
+ self ._integer = kwargs .pop ('integer' )
1961
+ if kwargs :
1962
+ key , _ = kwargs .popitem ()
1963
+ cbook .warn_deprecated ("3.1" ,
1964
+ message = "MaxNLocator.set_params got an "
1965
+ f"unexpected parameter: { key } " )
1929
1966
1930
1967
def _raw_ticks (self , vmin , vmax ):
1931
1968
"""
0 commit comments