8000 Merge pull request #13851 from anntzer/locform · matplotlib/matplotlib@5c791a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c791a8

Browse files
authored
Merge pull request #13851 from anntzer/locform
Deprecate setting Axis.major.locator to non-Locator; idem for Formatters
2 parents 4975a5e + eaf4437 commit 5c791a8

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Deprecations
2+
````````````
3+
4+
Setting ``Axis.major.locator``, ``Axis.minor.locator``, ``Axis.major.formatter``
5+
or ``Axis.minor.formatter`` to an object that is not a subclass of `Locator` or
6+
`Formatter` (respectively) is deprecated. Note that these attributes should
7+
usually be set using `Axis.set_major_locator`, `Axis.set_minor_locator`, etc.
8+
which already raise an exception when an object of the wrong class is passed.

lib/matplotlib/axis.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,36 @@ class Ticker(object):
640640
formatter : `matplotlib.ticker.Formatter` subclass
641641
Determines the format of the tick labels.
642642
"""
643-
locator = None
644-
formatter = None
643+
644+
def __init__(self):
645+
self._locator = None
646+
self._formatter = None
647+
648+
@property
649+
def locator(self):
650+
return self._locator
651+
652+
@locator.setter
653+
def locator(self, locator):
654+
if not isinstance(locator, mticker.Locator):
655+
cbook.warn_deprecated(
656+
"3.2", message="Support for locators that do not subclass "
657+
"matplotlib.ticker.Locator is deprecated since %(since)s and "
658+
"support for them will be removed %(removal)s.")
659+
self._locator = locator
660+
661+
@property
662+
def formatter(self):
663+
return self._formatter
664+
665+
@formatter.setter
666+
def formatter(self, formatter):
667+
if not isinstance(formatter, mticker.Formatter):
668+
cbook.warn_deprecated(
669+
"3.2", message="Support for formatters that do not subclass "
670+
"matplotlib.ticker.Formatter is deprecated since %(since)s "
671+
"and support for them will be removed %(removal)s.")
672+
self._formatter = formatter
645673

646674

647675
class _LazyTickList(object):

0 commit comments

Comments
 (0)
0