From d11ac6af38debef7ffd4c61bdef110caaf18b0b7 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 21 May 2019 12:09:28 +0100 Subject: [PATCH 1/4] Add more descriptive variable names --- lib/matplotlib/ticker.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 4c89181fa2b2..37753edf44aa 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -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 @@ -2469,21 +2469,21 @@ def tick_values(self, vmin, vmax): # t) -- it should just display (vmin, 0, vmax) 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: @@ -2492,22 +2492,22 @@ 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 if has_a: if has_b: - a_range = get_log_range(t, -vmin + 1) + a_range = get_log_range(linthresh, -vmin) else: - a_range = get_log_range(-vmax, -vmin + 1) + a_range = get_log_range(-vmax, -vmin) 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: @@ -2520,18 +2520,18 @@ def get_log_range(lo, hi): 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) From 6b312bf2529877704f86036cd6fe69c1dcac46e5 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 24 May 2019 13:16:40 +0200 Subject: [PATCH 2/4] Add some more comments and use np.abs() to make clear intent --- lib/matplotlib/ticker.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 37753edf44aa..7f5ee19b9140 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2468,6 +2468,7 @@ 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 has_a = has_b = has_c = False if vmin < -linthresh: has_a = True @@ -2496,12 +2497,12 @@ def get_log_range(lo, hi): 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(linthresh, -vmin) + a_range = get_log_range(linthresh, np.abs(vmin)) else: - a_range = get_log_range(-vmax, -vmin) + a_range = get_log_range(np.abs(vmax), np.abs(vmin)) else: a_range = (0, 0) @@ -2513,6 +2514,7 @@ def get_log_range(lo, hi): else: c_range = (0, 0) + # Caclulate 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 From 508d3b29d1e0efeffe298afc1659450a8357afe3 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 27 May 2019 11:51:42 +0100 Subject: [PATCH 3/4] Put back missing +1s --- lib/matplotlib/ticker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 7f5ee19b9140..8e081c86b178 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2500,9 +2500,9 @@ def get_log_range(lo, hi): # Calculate all the ranges, so we can determine striding if has_a: if has_b: - a_range = get_log_range(linthresh, np.abs(vmin)) + a_range = get_log_range(linthresh, np.abs(vmin) + 1) else: - a_range = get_log_range(np.abs(vmax), np.abs(vmin)) + a_range = get_log_range(np.abs(vmax), np.abs(vmin) + 1) else: a_range = (0, 0) From c39f4a64d430d5524707f428f4cfa52a714e6e3c Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 27 May 2019 13:52:00 +0100 Subject: [PATCH 4/4] Fix comment typo --- lib/matplotlib/ticker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 8e081c86b178..98c116fbe334 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2514,7 +2514,7 @@ def get_log_range(lo, hi): else: c_range = (0, 0) - # Caclulate the total number of integer exponents in a and c ranges + # 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