diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 12142b6edc04..2136015cf1b1 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -859,6 +859,22 @@ def test_set_use_offset_float(self): assert not tmp_form.get_useOffset() assert tmp_form.offset == 0.5 + def test_set_use_offset_bool(self): + tmp_form = mticker.ScalarFormatter() + tmp_form.set_useOffset(True) + assert tmp_form.get_useOffset() + assert tmp_form.offset == 0 + + tmp_form.set_useOffset(False) + assert not tmp_form.get_useOffset() + assert tmp_form.offset == 0 + + def test_set_use_offset_int(self): + tmp_form = mticker.ScalarFormatter() + tmp_form.set_useOffset(1) + assert not tmp_form.get_useOffset() + assert tmp_form.offset == 1 + def test_use_locale(self): conv = locale.localeconv() sep = conv['thousands_sep'] diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 231479092461..4eb9a2e66c01 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -510,7 +510,7 @@ def set_useOffset(self, val): will be formatted as ``0, 2, 4, 6, 8`` plus an offset ``+1e5``, which is written to the edge of the axis. """ - if val in [True, False]: + if isinstance(val, bool): self.offset = 0 self._useOffset = val else: