Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74fd787

Browse files
committed
Deprecate old and little used formatters.
- The new ScalarFormatter replaced OldScalarFormatter in 3910bb9 (2005). - IndexFormatter appeared in e66091d (2009) but was never used in the examples; IndexDateFormatter is unused in the docs since 4ea4b96 (2009); both can be fairly easily implemented in terms of FuncFormatter. I'm willing to back off the deprecations if there's demand to keep them, though.
1 parent bdcd9fc commit 74fd787

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,8 @@ This method is deprecated. Use
131131
``SymmetricalScale.SymmetricalTransform`` and
132132
``SymmetricalScale.InvertedSymmetricalTransform`` are deprecated. Directly
133133
access the transform classes from the :mod:`.scale` module.
134+
135+
``OldScalarFormatter``, ``IndexFormatter`` and ``DateIndexFormatter``
136+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
137+
These formatters are deprecated. Their functionality can be implemented using
138+
e.g. `.FuncFormatter`.

lib/matplotlib/dates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ def set_tzinfo(self, tz):
604604
self.tz = tz
605605

606606

607+
@cbook.deprecated("3.3")
607608
class IndexDateFormatter(ticker.Formatter):
608609
"""Use with `.IndexLocator` to cycle format strings by index."""
609610

lib/matplotlib/tests/test_ticker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111

1212
import matplotlib
13+
from matplotlib import cbook
1314
import matplotlib.pyplot as plt
1415
import matplotlib.ticker as mticker
1516

@@ -457,7 +458,8 @@ class TestIndexFormatter:
457458
(2, 'label2'),
458459
(2.5, '')])
459460
def test_formatting(self, x, label):
460-
formatter = mticker.IndexFormatter(['label0', 'label1', 'label2'])
461+
with cbook._suppress_matplotlib_deprecation_warning():
462+
formatter = mticker.IndexFormatter(['label0', 'label1', 'label2'])
461463
assert formatter(x) == label
462464

463465

lib/matplotlib/ticker.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ def _set_locator(self, locator):
299299
pass
300300

301301

302+
@cbook.deprecated("3.3")
302303
class IndexFormatter(Formatter):
303304
"""
304305
Format the position x to the nearest i-th label where ``i = int(x + 0.5)``.
@@ -328,13 +329,10 @@ def __call__(self, x, pos=None):
328329

329330

330331
class NullFormatter(Formatter):
331-
"""
332-
Always return the empty string.
333-
"""
332+
"""Always return the empty string."""
333+
334334
def __call__(self, x, pos=None):
335-
"""
336-
Returns an empty string for all inputs.
337-
"""
335+
# docstring inherited
338336
return ''
339337

340338

0 commit comments

Comments
 (0)