Skip to content

Commit cf2386a

Browse files
committed
Deprecate public use of Formatter.pprint_val.
It's really a helper method.
1 parent 369618a commit cf2386a

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``OldScalarFormatter.pprint_val``, ``ScalarFormatter.pprint_val``, and ``LogFormatter.pprint_val`` are deprecated
2+
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````
3+
They are helper methods that do not even have a consistent signatures across formatter classes.

lib/matplotlib/ticker.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,13 @@ def _set_locator(self, locator):
294294
""" Subclasses may want to override this to set a locator. """
295295
pass
296296

297+
@cbook.deprecated("3.1")
298+
def pprint_val(self, *args, **kwargs):
299+
return self._pprint_val(*args, **kwargs)
300+
301+
def _pprint_val(self, *args, **kwargs):
302+
raise NotImplementedError
303+
297304

298305
class IndexFormatter(Formatter):
299306
"""
@@ -428,22 +435,19 @@ class OldScalarFormatter(Formatter):
428435

429436
def __call__(self, x, pos=None):
430437
"""
431-
Return the format for tick val `x` based on the width of the
432-
axis.
438+
Return the format for tick val `x` based on the width of the axis.
433439
434440
The position `pos` is ignored.
435441
"""
436442
xmin, xmax = self.axis.get_view_interval()
437443
d = abs(xmax - xmin)
444+
return self._pprint_val(x, d)
438445

439-
return self.pprint_val(x, d)
440-
441-
def pprint_val(self, x, d):
446+
def _pprint_val(self, x, d):
442447
"""
443448
Formats the value `x` based on the size of the axis range `d`.
444449
"""
445-
#if the number is not too big and it's an int, format it as an
446-
#int
450+
# If the number is not too big and it's an int, format it as an int.
447451
if abs(x) < 1e4 and x == int(x):
448452
return '%d' % x
449453

@@ -555,7 +559,7 @@ def __call__(self, x, pos=None):
555559
if len(self.locs) == 0:
556560
return ''
557561
else:
558-
s = self.pprint_val(x)
562+
s = self._pprint_val(x)
559563
return self.fix_minus(s)
560564

561565
def set_scientific(self, b):
@@ -766,7 +770,7 @@ def _set_format(self, vmin, vmax):
766770
elif self._useMathText:
767771
self.format = '$%s$' % _mathdefault(self.format)
768772

769-
def pprint_val(self, x):
773+
def _pprint_val(self, x):
770774
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
771775
if np.abs(xp) < 1e-8:
772776
xp = 0
@@ -966,7 +970,7 @@ def _num_to_string(self, x, vmin, vmax):
966970
elif x < 1:
967971
s = '%1.0e' % x
968972
else:
969-
s = self.pprint_val(x, vmax - vmin)
973+
s = self._pprint_val(x, vmax - vmin)
970974
return s
971975

972976
def __call__(self, x, pos=None):
@@ -1007,9 +1011,8 @@ def format_data_short(self, value):
10071011
"""
10081012
return '%-12g' % value
10091013

1010-
def pprint_val(self, x, d):
1011-
#if the number is not too big and it's an int, format it as an
1012-
#int
1014+
def _pprint_val(self, x, d):
1015+
# If the number is not too big and it's an int, format it as an int.
10131016
if abs(x) < 1e4 and x == int(x):
10141017
return '%d' % x
10151018

@@ -1052,7 +1055,7 @@ def _num_to_string(self, x, vmin, vmax):
10521055
s = '%1.0g' % fx
10531056
else:
10541057
fd = math.log(vmax - vmin) / math.log(self._base)
1055-
s = self.pprint_val(fx, fd)
1058+
s = self._pprint_val(fx, fd)
10561059
return s
10571060

10581061

0 commit comments

Comments
 (0)