From b74e128c9764b49563f3606f43bd095da5599f67 Mon Sep 17 00:00:00 2001 From: Ryan May Date: Tue, 25 Sep 2018 20:55:35 -0400 Subject: [PATCH] BUG: Fix typo in view_limits() for MultipleLocator --- lib/matplotlib/tests/test_ticker.py | 17 +++++++++++++++++ lib/matplotlib/ticker.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 9d3501059799..52319d7c12ad 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -59,6 +59,23 @@ def test_basic(self): 9.441, 12.588]) assert_almost_equal(loc.tick_values(-7, 10), test_value) + def test_view_limits(self): + """ + Test basic behavior of view limits. + """ + with matplotlib.rc_context({'axes.autolimit_mode': 'data'}): + loc = mticker.MultipleLocator(base=3.147) + assert_almost_equal(loc.view_limits(-5, 5), (-5, 5)) + + def test_view_limits_round_numbers(self): + """ + Test that everything works properly with 'round_numbers' for auto + limit. + """ + with matplotlib.rc_context({'axes.autolimit_mode': 'round_numbers'}): + loc = mticker.MultipleLocator(base=3.147) + assert_almost_equal(loc.view_limits(-4, 4), (-6.294, 6.294)) + def test_set_params(self): """ Create multiple locator with 0.7 base, and change it to something else. diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index a7487144885e..743ec642b48d 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1750,7 +1750,7 @@ def view_limits(self, dmin, dmax): """ if rcParams['axes.autolimit_mode'] == 'round_numbers': vmin = self._edge.le(dmin) * self._edge.step - vmax = self._base.ge(dmax) * self._edge.step + vmax = self._edge.ge(dmax) * self._edge.step if vmin == vmax: vmin -= 1 vmax += 1