Skip to content

Small clean to SymmetricalLogLocator #14308

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 4 commits into from
May 31, 2019
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
38 changes: 20 additions & 18 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2442,8 +2442,8 @@ def __call__(self):
return self.tick_values(vmin, vmax)

def tick_values(self, vmin, vmax):
b = self._base
t = self._linthresh
base = self._base
linthresh = self._linthresh

if vmax < vmin:
vmin, vmax = vmax, vmin
Expand All @@ -2468,22 +2468,23 @@ def tick_values(self, vmin, vmax):
# "simple" mode is when the range falls entirely within (-t,
# t) -- it should just display (vmin, 0, vmax)

# Determine which of the three ranges we have
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the whole thing can be simplified to

if -linthresh <= vmin <= vmax <= 0 or 0 <= vmin <= vmax <= linthresh:
    return [vmin, vmax]
has_a = (vmin < -linthresh)
has_b = (-linthresh < vmin < linthresh or -linthresh < vmax < linthresh)
has_c = (linthresh < vmax)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think SymLogNorm needs quite a few more tests, which I plan to add in for 3.2 at some point; I think this is a good suggestion, but might save it for after I've written tests that exercise this logic properly.

Copy link
Contributor

Choose a reason for hiding this comment

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

sure

has_a = has_b = has_c = False
if vmin < -t:
if vmin < -linthresh:
has_a = True
if vmax > -t:
if vmax > -linthresh:
has_b = True
if vmax > t:
if vmax > linthresh:
has_c = True
elif vmin < 0:
if vmax > 0:
has_b = True
if vmax > t:
if vmax > linthresh:
has_c = True
else:
return [vmin, vmax]
elif vmin < t:
if vmax > t:
elif vmin < linthresh:
if vmax > linthresh:
has_b = True
has_c = True
else:
Expand All @@ -2492,46 +2493,47 @@ def tick_values(self, vmin, vmax):
has_c = True

def get_log_range(lo, hi):
lo = np.floor(np.log(lo) / np.log(b))
hi = np.ceil(np.log(hi) / np.log(b))
lo = np.floor(np.log(lo) / np.log(base))
hi = np.ceil(np.log(hi) / np.log(base))
return lo, hi

# First, calculate all the ranges, so we can determine striding
# Calculate all the ranges, so we can determine striding
if has_a:
if has_b:
a_range = get_log_range(t, -vmin + 1)
a_range = get_log_range(linthresh, np.abs(vmin) + 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

can use (builtin) abs() instead of np.abs()

else:
a_range = get_log_range(-vmax, -vmin + 1)
a_range = get_log_range(np.abs(vmax), np.abs(vmin) + 1)
else:
a_range = (0, 0)

if has_c:
if has_b:
c_range = get_log_range(t, vmax + 1)
c_range = get_log_range(linthresh, vmax + 1)
else:
c_range = get_log_range(vmin, vmax + 1)
else:
c_range = (0, 0)

# Calculate the total number of integer exponents in a and c ranges
total_ticks = (a_range[1] - a_range[0]) + (c_range[1] - c_range[0])
if has_b:
total_ticks += 1
stride = max(total_ticks // (self.numticks - 1), 1)

decades = []
if has_a:
decades.extend(-1 * (b ** (np.arange(a_range[0], a_range[1],
stride)[::-1])))
decades.extend(-1 * (base ** (np.arange(a_range[0], a_range[1],
stride)[::-1])))

if has_b:
decades.append(0.0)

if has_c:
decades.extend(b ** (np.arange(c_range[0], c_range[1], stride)))
decades.extend(base ** (np.arange(c_range[0], c_range[1], stride)))

# Add the subticks if requested
if self._subs is None:
subs = np.arange(2.0, b)
subs = np.arange(2.0, base)
else:
subs = np.asarray(self._subs)

Expand Down