Skip to content

Commit 53893d0

Browse files
committed
ENH: Made self.formatter not have to be an actual instace of Formatter
1 parent 15898e0 commit 53893d0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/matplotlib/ticker.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,9 @@ class LinearScaleFormatter(Formatter):
13881388
interpreted as ``(0, outRef)``.
13891389
formatter: matplotlib.ticker.Formatter
13901390
The instance to delegate the actual formatting of the
1391-
transformed value to.
1391+
transformed value to. This does not have to be an instance of
1392+
``matplotlib.ticker.Formatter``. Any callable that accepts ``x``
1393+
and ``pos`` as arguments and returns a string will work.
13921394
"""
13931395
def __init__(self, inRef=1.0, outRef=1.0, formatter=ScalarFormatter()):
13941396
def unpack(ref, name):
@@ -1420,16 +1422,22 @@ def __call__(self, x, pos=None):
14201422
return self.formatter(self.transform(x), pos)
14211423

14221424
def set_axis(self, ax):
1423-
self.formatter.set_axis(ax)
1425+
if hasattr(self.formatter, 'set_axis'):
1426+
self.formatter.set_axis(ax)
14241427

14251428
def get_offset(self):
1426-
return self.formatter.get_offset()
1429+
if hasattr(self.formatter, 'get_axis'):
1430+
return self.formatter.get_offset()
1431+
return super(LinearScaleFormatter, self).get_offset()
14271432

14281433
def set_locs(self, locs):
1429-
self.formatter.set_locs([self.transform(x) for x in locs])
1434+
if hasattr(self.formatter, 'set_locs'):
1435+
self.formatter.set_locs([self.transform(x) for x in locs])
14301436

14311437
def fix_minus(self, s):
1432-
return self.formatter.fix_minus(s)
1438+
if hasattr(self.formatter, 'fix_minus'):
1439+
return self.formatter.fix_minus(s)
1440+
return super(LinearScaleFormatter, self).fix_minus(s)
14331441

14341442

14351443
class Locator(TickHelper):

0 commit comments

Comments
 (0)