Skip to content

Commit d72f069

Browse files
authored
Merge pull request #12924 from anntzer/pprint_val
API: Deprecate public use of Formatter.pprint_val.
2 parents f4b2b68 + c5a38ad commit d72f069

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
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

+21-13
Original file line numberDiff line numberDiff line change
@@ -428,22 +428,23 @@ class OldScalarFormatter(Formatter):
428428

429429
def __call__(self, x, pos=None):
430430
"""
431-
Return the format for tick val `x` based on the width of the
432-
axis.
431+
Return the format for tick val `x` based on the width of the axis.
433432
434433
The position `pos` is ignored.
435434
"""
436435
xmin, xmax = self.axis.get_view_interval()
437436
d = abs(xmax - xmin)
437+
return self._pprint_val(x, d)
438438

439-
return self.pprint_val(x, d)
439+
@cbook.deprecated("3.1")
440+
def pprint_val(self, *args, **kwargs):
441+
return self._pprint_val(*args, **kwargs)
440442

441-
def pprint_val(self, x, d):
443+
def _pprint_val(self, x, d):
442444
"""
443445
Formats the value `x` based on the size of the axis range `d`.
444446
"""
445-
#if the number is not too big and it's an int, format it as an
446-
#int
447+
# If the number is not too big and it's an int, format it as an int.
447448
if abs(x) < 1e4 and x == int(x):
448449
return '%d' % x
449450

@@ -555,7 +556,7 @@ def __call__(self, x, pos=None):
555556
if len(self.locs) == 0:
556557
return ''
557558
else:
558-
s = self.pprint_val(x)
559+
s = self._pprint_val(x)
559560
return self.fix_minus(s)
560561

561562
def set_scientific(self, b):
@@ -766,7 +767,11 @@ def _set_format(self, vmin, vmax):
766767
elif self._useMathText:
767768
self.format = '$%s$' % _mathdefault(self.format)
768769

769-
def pprint_val(self, x):
770+
@cbook.deprecated("3.1")
771+
def pprint_val(self, *args, **kwargs):
772+
return self._pprint_val(*args, **kwargs)
773+
774+
def _pprint_val(self, x):
770775
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
771776
if np.abs(xp) < 1e-8:
772777
xp = 0
@@ -966,7 +971,7 @@ def _num_to_string(self, x, vmin, vmax):
966971
elif x < 1:
967972
s = '%1.0e' % x
968973
else:
969-
s = self.pprint_val(x, vmax - vmin)
974+
s = self._pprint_val(x, vmax - vmin)
970975
return s
971976

972977
def __call__(self, x, pos=None):
@@ -1007,9 +1012,12 @@ def format_data_short(self, value):
10071012
"""
10081013
return '%-12g' % value
10091014

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
1015+
@cbook.deprecated("3.1")
1016+
def pprint_val(self, *args, **kwargs):
1017+
return self._pprint_val(*args, **kwargs)
1018+
1019+
def _pprint_val(self, x, d):
1020+
# If the number is not too big and it's an int, format it as an int.
10131021
if abs(x) < 1e4 and x == int(x):
10141022
return '%d' % x
10151023

@@ -1052,7 +1060,7 @@ def _num_to_string(self, x, vmin, vmax):
10521060
s = '%1.0g' % fx
10531061
else:
10541062
fd = math.log(vmax - vmin) / math.log(self._base)
1055-
s = self.pprint_val(fx, fd)
1063+
s = self._pprint_val(fx, fd)
10561064
return s
10571065

10581066

0 commit comments

Comments
 (0)