Skip to content

Updated argument to mpl.ticker.LogFormatter.label_minor #6264

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

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 18 additions & 18 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,13 +829,13 @@ class LogFormatter(Formatter):
"""
Format values for log axis.
"""
def __init__(self, base=10.0, labelOnlyBase=True):
def __init__(self, base=10.0, label_only_base=True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fix has to hold off until we have python3 only and can do

def __init__(self, base, label_only_base, * labelOnlyBase=none)

and then deprecate it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can do this for both with

def __init__(self, base, label_only_base=True,  **kwargs)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The easiest way to do this is …, label_only_base=True, labelOnlyBase=None and check whether labelOnlyBase was provided to deprecate it.

"""
`base` is used to locate the decade tick, which will be the only
one to be labeled if `labelOnlyBase` is ``True``.
one to be labeled if `label_only_base` is ``True``.
"""
self._base = base + 0.0
self.labelOnlyBase = labelOnlyBase
self.label_only_base = label_only_base
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a public API break which should be patched over with a property, but should also wait for changing the parameter name in the __init__

self.sublabel = [1, ]

def base(self, base):
Expand All @@ -848,13 +848,13 @@ def base(self, base):
"""
self._base = base

def label_minor(self, labelOnlyBase):
def label_minor(self, label_only_base):
"""
Switch minor tick labeling on or off.
Switch intermediate tick labeling on or off.

``labelOnlyBase=True`` to turn off minor ticks.
``label_only_base=True`` to turn off minor (non-decade) ticks.
"""
self.labelOnlyBase = labelOnlyBase
self.label_only_base = label_only_base

def set_locs(self, locs):
b = self._base
Expand Down Expand Up @@ -903,11 +903,11 @@ def __call__(self, x, pos=None):
x = abs(x)
# only label the decades
fx = math.log(x) / math.log(b)
isDecade = is_close_to_int(fx)
exponent = np.round(fx) if isDecade else np.floor(fx)
is_decade = is_close_to_int(fx)
exponent = np.round(fx) if is_decade else np.floor(fx)
coeff = np.round(x / b ** exponent)
if coeff in self.sublabel:
if not isDecade and self.labelOnlyBase:
if not is_decade and self.label_only_base:
return ''
elif x > 10000:
s = '%1.0e' % x
Expand All @@ -923,10 +923,10 @@ def __call__(self, x, pos=None):
return self.fix_minus(s)

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

def format_data_short(self, value):
Expand Down Expand Up @@ -987,8 +987,8 @@ def __call__(self, x, pos=None):
sign = np.sign(x)
# only label the decades
fx = math.log(abs(x)) / math.log(b)
isDecade = is_close_to_int(fx)
if not isDecade and self.labelOnlyBase:
is_decade = is_close_to_int(fx)
if not is_decade and self.label_only_base:
s = ''
elif abs(fx) > 10000:
s = '%1.0g' % fx
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def __call__(self, x, pos=None):
base = '%s' % b

if coeff in self.sublabel:
if not is_decade and self.labelOnlyBase:
if not is_decade and self.label_only_basee:
return ''
elif not is_decade:
return self._non_decade_format(sign_string, base, fx, usetex)
Expand All @@ -1068,9 +1068,9 @@ class LogFormatterSciNotation(LogFormatterMathtext):
Format values following scientific notation in a logarithmic axis
"""

def __init__(self, base=10.0, labelOnlyBase=False):
def __init__(self, base=10.0, label_only_base=False):
super(LogFormatterSciNotation, self).__init__(base=base,
labelOnlyBase=labelOnlyBase)
label_only_base=label_only_base)

def _non_decade_format(self, sign_string, base, fx, usetex):
'Return string for non-decade locations'
Expand Down