Skip to content

Commit 1c61b06

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 7c04486 commit 1c61b06

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

doc/api/next_api_changes/deprecations.rst

+9
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,12 @@ and containment checks) via `.Line2D.set_picker` is deprecated. Use
150150
The ``on_mappable_changed`` and ``update_bruteforce`` methods of
151151
`~matplotlib.colorbar.Colorbar` are deprecated; both can be replaced by calls
152152
to `~matplotlib.colorbar.Colorbar.update_normal`.
153+
154+
``OldScalarFormatter``, ``IndexFormatter`` and ``DateIndexFormatter``
155+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156+
These formatters are deprecated. Their functionality can be implemented using
157+
e.g. `.FuncFormatter`.
158+
159+
``OldAutoLocator``
160+
~~~~~~~~~~~~~~~~~~
161+
This ticker is deprecated.

lib/matplotlib/dates.py

+1
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

+3-1
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def _set_locator(self, locator):
293293
pass
294294

295295

296+
@cbook.deprecated("3.3")
296297
class IndexFormatter(Formatter):
297298
"""
298299
Format the position x to the nearest i-th label where ``i = int(x + 0.5)``.
@@ -322,13 +323,10 @@ def __call__(self, x, pos=None):
322323

323324

324325
class NullFormatter(Formatter):
325-
"""
326-
Always return the empty string.
327-
"""
326+
"""Always return the empty string."""
327+
328328
def __call__(self, x, pos=None):
329-
"""
330-
Returns an empty string for all inputs.
331-
"""
329+
# docstring inherited
332330
return ''
333331

334332

@@ -428,6 +426,7 @@ def __call__(self, x, pos=None):
428426
return self.fmt.format(x=x, pos=pos)
429427

430428

429+
@cbook.deprecated("3.3")
431430
class OldScalarFormatter(Formatter):
432431
"""
433432
Tick location is a plain old number.
@@ -2867,6 +2866,7 @@ def tick_values(self, vmin, vmax):
28672866
'%s type.' % type(self))
28682867

28692868

2869+
@cbook.deprecated("3.3")
28702870
class OldAutoLocator(Locator):
28712871
"""
28722872
On autoscale this class picks the best MultipleLocator to set the

0 commit comments

Comments
 (0)