diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 15f0881af176..77b909a4cf59 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 71f798a20afa..9226ddf6e0f7 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1742,7 +1742,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