diff --git a/doc/api/next_api_changes/2019-04-02-AL.rst b/doc/api/next_api_changes/2019-04-02-AL.rst new file mode 100644 index 000000000000..88fdfc992a93 --- /dev/null +++ b/doc/api/next_api_changes/2019-04-02-AL.rst @@ -0,0 +1,8 @@ +Deprecations +```````````` + +Setting ``Axis.major.locator``, ``Axis.minor.locator``, ``Axis.major.formatter`` +or ``Axis.minor.formatter`` to an object that is not a subclass of `Locator` or +`Formatter` (respectively) is deprecated. Note that these attributes should +usually be set using `Axis.set_major_locator`, `Axis.set_minor_locator`, etc. +which already raise an exception when an object of the wrong class is passed. diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 1a903733de86..d874d052b6d9 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -640,8 +640,36 @@ class Ticker(object): formatter : `matplotlib.ticker.Formatter` subclass Determines the format of the tick labels. """ - locator = None - formatter = None + + def __init__(self): + self._locator = None + self._formatter = None + + @property + def locator(self): + return self._locator + + @locator.setter + def locator(self, locator): + if not isinstance(locator, mticker.Locator): + cbook.warn_deprecated( + "3.2", message="Support for locators that do not subclass " + "matplotlib.ticker.Locator is deprecated since %(since)s and " + "support for them will be removed %(removal)s.") + self._locator = locator + + @property + def formatter(self): + return self._formatter + + @formatter.setter + def formatter(self, formatter): + if not isinstance(formatter, mticker.Formatter): + cbook.warn_deprecated( + "3.2", message="Support for formatters that do not subclass " + "matplotlib.ticker.Formatter is deprecated since %(since)s " + "and support for them will be removed %(removal)s.") + self._formatter = formatter class _LazyTickList(object):