From 339d7627ba0afbe5c5612ca3abf8e4fc7ada7875 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Mon, 7 Jan 2019 09:40:07 -0800 Subject: [PATCH 1/4] FIX: log axes: don't choose major ticks as a minor tick --- lib/matplotlib/ticker.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 89e077a04262..84bd9a2b4718 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2093,9 +2093,7 @@ def is_decade(x, base=10): def is_close_to_int(x): - if not np.isfinite(x): - return False - return abs(x - round(x)) < 1e-10 + return abs(x - np.round(x)) < 1e-10 class LogLocator(Locator): @@ -2256,7 +2254,11 @@ def tick_values(self, vmin, vmax): # If we're a minor locator *that expects at least two ticks per # decade* and the major locator stride is 1 and there's no more # than one minor tick, switch to AutoLocator. - return AutoLocator().tick_values(vmin, vmax) + ticklocs = AutoLocator().tick_values(vmin, vmax) + # Don't overstrike the major labels. + ticklocs = ticklocs[ + ~is_close_to_int(np.log(ticklocs) / np.log(b))] + return ticklocs return self.raise_if_exceeds(ticklocs) def view_limits(self, vmin, vmax): From 5e6031493dafe67d7c2215e72a5ebbf35b12adb7 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 9 Jan 2019 09:41:03 -0800 Subject: [PATCH 2/4] TST: add test --- lib/matplotlib/tests/test_ticker.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index b0ecb72dfdb4..02c2ecfaeff0 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -183,6 +183,10 @@ def test_switch_to_autolocator(self): loc = mticker.LogLocator(subs="all") assert_array_equal(loc.tick_values(0.45, 0.55), [0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56]) + # check that we *skip* 1.0, and 10, because this is a minor locator + loc = mticker.LogLocator(subs=np.arange(2, 10)) + assert 1.0 not in loc.tick_values(0.9, 20.) + assert 10.0 not in loc.tick_values(0.9, 20.) def test_set_params(self): """ From 419f6d3d45ea9c2381aba450a3b77a426cccb616 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 10 Jan 2019 09:57:27 -0800 Subject: [PATCH 3/4] DOC: slightly better commenting --- lib/matplotlib/ticker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 84bd9a2b4718..0d1cc1d2a531 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2255,7 +2255,8 @@ def tick_values(self, vmin, vmax): # decade* and the major locator stride is 1 and there's no more # than one minor tick, switch to AutoLocator. ticklocs = AutoLocator().tick_values(vmin, vmax) - # Don't overstrike the major labels. + # Don't overstrike the major labels. Assumes major locs are + # at b = self._base ticklocs = ticklocs[ ~is_close_to_int(np.log(ticklocs) / np.log(b))] return ticklocs From 1f70d7a28b4a40e2f8ab774153b8445c4b19e9fb Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 10 Jan 2019 15:25:01 -0800 Subject: [PATCH 4/4] Strike trailing white space --- 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 0d1cc1d2a531..c68ef258dcd9 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2256,7 +2256,7 @@ def tick_values(self, vmin, vmax): # than one minor tick, switch to AutoLocator. ticklocs = AutoLocator().tick_values(vmin, vmax) # Don't overstrike the major labels. Assumes major locs are - # at b = self._base + # at b = self._base ticklocs = ticklocs[ ~is_close_to_int(np.log(ticklocs) / np.log(b))] return ticklocs