Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Simple cleanups to formatters. #16786

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
Mar 18, 2020
Merged
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
29 changes: 7 additions & 22 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,8 @@ class LogFormatter(Formatter):

To label all minor ticks when the view limits span up to 1.5
decades, use ``minor_thresholds=(1.5, 1.5)``.

"""

def __init__(self, base=10.0, labelOnlyBase=False,
minor_thresholds=None,
linthresh=None):
Expand All @@ -857,7 +857,6 @@ def base(self, base):

.. warning::
Should always match the base used for :class:`LogLocator`

"""
self._base = base

Expand All @@ -869,7 +868,6 @@ def label_minor(self, labelOnlyBase):
----------
labelOnlyBase : bool
If True, label ticks only at integer powers of base.

"""
self.labelOnlyBase = labelOnlyBase

Expand All @@ -878,7 +876,6 @@ def set_locs(self, locs=None):
Use axis view limits to control which ticks are labeled.

The *locs* parameter is ignored in the present algorithm.

"""
if np.isinf(self.minor_thresholds[0]):
self._sublabels = None
Expand Down Expand Up @@ -943,9 +940,7 @@ def _num_to_string(self, x, vmin, vmax):
return s

def __call__(self, x, pos=None):
"""
Return the format for tick val *x*.
"""
# docstring inherited
if x == 0.0: # Symlog
return '0'

Expand All @@ -968,11 +963,8 @@ def __call__(self, x, pos=None):
return s

def format_data(self, value):
b = self.labelOnlyBase
self.labelOnlyBase = False
value = cbook.strip_math(self.__call__(value))
self.labelOnlyBase = b
return value
with cbook._setattr_cm(self, labelOnlyBase=False):
return cbook.strip_math(self.__call__(value))

def format_data_short(self, value):
# docstring inherited
Expand Down Expand Up @@ -1027,11 +1019,7 @@ def _non_decade_format(self, sign_string, base, fx, usetex):
return r'$\mathdefault{%s%s^{%.2f}}$' % (sign_string, base, fx)

def __call__(self, x, pos=None):
"""
Return the format for tick value *x*.

The position *pos* is ignored.
"""
# docstring inherited
usetex = mpl.rcParams['text.usetex']
min_exp = mpl.rcParams['axes.formatter.min_exponent']

Expand Down Expand Up @@ -1271,11 +1259,8 @@ def __call__(self, x, pos=None):
return r"$\mathdefault{%s}$" % s

def format_data_short(self, value):
"""
Return a short formatted string representation of a number.
"""
# thresholds choosen for use scienfic notation if and only if exponent
# is less or equal than -2.
# docstring inherited
# Thresholds chosen to use scientific notation iff exponent <= -2.
if value < 0.1:
return "{:e}".format(value)
if value < 0.9:
Expand Down