Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7c46d33

Browse filesBrowse files
committed
Init MaxNLocator params only once
1 parent dba2d7b commit 7c46d33
Copy full SHA for 7c46d33

File tree

Expand file treeCollapse file tree

2 files changed

+46
-14
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+46
-14
lines changed
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Deprecations
2+
````````````
3+
4+
The class variable ``matplotlib.ticker.MaxNLocator.default_params`` is
5+
deprecated and will be removed in a future version. The defaults are not
6+
supposed to be user-configurable.
7+
8+
``matplotlib.ticker.MaxNLocator`` and its ``set_params`` method will issue
9+
a warning on unknown keyword arguments instead of silently ignoring them.
10+
Future versions will raise an error.

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+36-14Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,12 +1824,12 @@ class MaxNLocator(Locator):
18241824
"""
18251825
Select no more than N intervals at nice locations.
18261826
"""
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)
18331833

18341834
def __init__(self, *args, **kwargs):
18351835
"""
@@ -1873,12 +1873,17 @@ def __init__(self, *args, **kwargs):
18731873
18741874
"""
18751875
if args:
1876+
if 'nbins' in kwargs:
1877+
cbook.deprecated("3.1",
1878+
message='Calling MaxNLocator with positional '
1879+
'and keyword parameter *nbins* is '
1880+
'considered an error and will fail '
1881+
'in future versions of matplotlib.')
18761882
kwargs['nbins'] = args[0]
18771883
if len(args) > 1:
18781884
raise ValueError(
18791885
"Keywords are required for all arguments except 'nbins'")
1880-
self.set_params(**self.default_params)
1881-
self.set_params(**kwargs)
1886+
self.set_params(**{**self._default_params, **kwargs})
18821887

18831888
@staticmethod
18841889
def _validate_steps(steps):
@@ -1895,6 +1900,16 @@ def _validate_steps(steps):
18951900
steps = np.hstack((steps, 10))
18961901
return steps
18971902

1903+
@cbook.deprecated("3.1")
1904+
@property
1905+
def default_params(self):
1906+
return self._default_params
1907+
1908+
@cbook.deprecated("3.1")
1909+
@default_params.setter
1910+
def default_params(self, params):
1911+
self._default_params = params
1912+
18981913
@staticmethod
18991914
def _staircase(steps):
19001915
# Make an extended staircase within which the needed
@@ -1906,28 +1921,35 @@ def _staircase(steps):
19061921
def set_params(self, **kwargs):
19071922
"""Set parameters within this locator."""
19081923
if 'nbins' in kwargs:
1909-
self._nbins = kwargs['nbins']
1924+
self._nbins = kwargs.pop('nbins')
19101925
if self._nbins != 'auto':
19111926
self._nbins = int(self._nbins)
19121927
if 'symmetric' in kwargs:
1913-
self._symmetric = kwargs['symmetric']
1928+
self._symmetric = kwargs.pop('symmetric')
19141929
if 'prune' in kwargs:
1915-
prune = kwargs['prune']
1930+
prune = kwargs.pop('prune')
19161931
if prune is not None and prune not in ['upper', 'lower', 'both']:
19171932
raise ValueError(
19181933
"prune must be 'upper', 'lower', 'both', or None")
19191934
self._prune = prune
19201935
if 'min_n_ticks' in kwargs:
1921-
self._min_n_ticks = max(1, kwargs['min_n_ticks'])
1936+
self._min_n_ticks = max(1, kwargs.pop('min_n_ticks'))
19221937
if 'steps' in kwargs:
1923-
steps = kwargs['steps']
1938+
steps = kwargs.pop('steps')
19241939
if steps is None:
19251940
self._steps = np.array([1, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10])
19261941
else:
19271942
self._steps = self._validate_steps(steps)
19281943
self._extended_steps = self._staircase(self._steps)
19291944
if 'integer' in kwargs:
1930-
self._integer = kwargs['integer']
1945+
self._integer = kwargs.pop('integer')
1946+
if kwargs:
1947+
param = next(k for k in kwargs)
1948+
cbook.warn_deprecated("3.1",
1949+
message="MaxNLocator.set_params got an "
1950+
f"unexpected parameter: {param}")
1951+
1952+
19311953

19321954
def _raw_ticks(self, vmin, vmax):
19331955
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.