Skip to content

Backport PR #22066 on branch v3.5.x (FIX: Remove trailing zeros from offset significand) #22074

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
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
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,13 @@ class TestScalarFormatter:
[12.3, "12.300"],
]

format_data = [
(.1, "1e-1"),
(.11, "1.1e-1"),
(1e8, "1e8"),
(1.1e8, "1.1e8"),
]

@pytest.mark.parametrize('unicode_minus, result',
[(True, "\N{MINUS SIGN}1"), (False, "-1")])
def test_unicode_minus(self, unicode_minus, result):
Expand Down Expand Up @@ -561,6 +568,12 @@ def test_scilimits(self, sci_type, scilimits, lim, orderOfMag, fewticks):
tmp_form.set_locs(ax.yaxis.get_majorticklocs())
assert orderOfMag == tmp_form.orderOfMagnitude

@pytest.mark.parametrize('value, expected', format_data)
def test_format_data(self, value, expected):
mpl.rcParams['axes.unicode_minus'] = False
sf = mticker.ScalarFormatter()
assert sf.format_data(value) == expected

@pytest.mark.parametrize('data, expected', cursor_data)
def test_cursor_precision(self, data, expected):
fig, ax = plt.subplots()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def format_data(self, value):
s = round(value / 10**e, 10)
exponent = self._format_maybe_minus_and_locale("%d", e)
significand = self._format_maybe_minus_and_locale(
"%d" if s % 1 == 0 else "%1.10f", s)
"%d" if s % 1 == 0 else "%1.10g", s)
if e == 0:
return significand
elif self._useMathText or self._usetex:
Expand Down