Skip to content

Fix: Ensure ScalarFormatter.set_useOffset properly distinguishes betw… #29537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading