Skip to content

Deprecate public use of Formatter.pprint_val. #12924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api/next_api_changes/2018-12-03-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``OldScalarFormatter.pprint_val``, ``ScalarFormatter.pprint_val``, and ``LogFormatter.pprint_val`` are deprecated
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````
They are helper methods that do not even have a consistent signatures across formatter classes.
34 changes: 21 additions & 13 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,22 +428,23 @@ class OldScalarFormatter(Formatter):

def __call__(self, x, pos=None):
"""
Return the format for tick val `x` based on the width of the
axis.
Return the format for tick val `x` based on the width of the axis.

The position `pos` is ignored.
"""
xmin, xmax = self.axis.get_view_interval()
d = abs(xmax - xmin)
return self._pprint_val(x, d)

return self.pprint_val(x, d)
@cbook.deprecated("3.1")
def pprint_val(self, *args, **kwargs):
return self._pprint_val(*args, **kwargs)

def pprint_val(self, x, d):
def _pprint_val(self, x, d):
"""
Formats the value `x` based on the size of the axis range `d`.
"""
#if the number is not too big and it's an int, format it as an
#int
# If the number is not too big and it's an int, format it as an int.
if abs(x) < 1e4 and x == int(x):
return '%d' % x

Expand Down Expand Up @@ -555,7 +556,7 @@ def __call__(self, x, pos=None):
if len(self.locs) == 0:
return ''
else:
s = self.pprint_val(x)
s = self._pprint_val(x)
return self.fix_minus(s)

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

def pprint_val(self, x):
@cbook.deprecated("3.1")
def pprint_val(self, *args, **kwargs):
return self._pprint_val(*args, **kwargs)

def _pprint_val(self, x):
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
if np.abs(xp) < 1e-8:
xp = 0
Expand Down Expand Up @@ -966,7 +971,7 @@ def _num_to_string(self, x, vmin, vmax):
elif x < 1:
s = '%1.0e' % x
else:
s = self.pprint_val(x, vmax - vmin)
s = self._pprint_val(x, vmax - vmin)
return s

def __call__(self, x, pos=None):
Expand Down Expand Up @@ -1007,9 +1012,12 @@ def format_data_short(self, value):
"""
return '%-12g' % value

def pprint_val(self, x, d):
#if the number is not too big and it's an int, format it as an
#int
@cbook.deprecated("3.1")
def pprint_val(self, *args, **kwargs):
return self._pprint_val(*args, **kwargs)

def _pprint_val(self, x, d):
# If the number is not too big and it's an int, format it as an int.
if abs(x) < 1e4 and x == int(x):
return '%d' % x

Expand Down Expand Up @@ -1052,7 +1060,7 @@ def _num_to_string(self, x, vmin, vmax):
s = '%1.0g' % fx
else:
fd = math.log(vmax - vmin) / math.log(self._base)
s = self.pprint_val(fx, fd)
s = self._pprint_val(fx, fd)
return s


Expand Down