Skip to content

Commit 51a0a10

Browse files
authored
Merge pull request #22074 from meeseeksmachine/auto-backport-of-pr-22066-on-v3.5.x
Backport PR #22066 on branch v3.5.x (FIX: Remove trailing zeros from offset significand)
2 parents 3466dd7 + bc2b971 commit 51a0a10

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/tests/test_ticker.py

+13
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,13 @@ class TestScalarFormatter:
500500
[12.3, "12.300"],
501501
]
502502

503+
format_data = [
504+
(.1, "1e-1"),
505+
(.11, "1.1e-1"),
506+
(1e8, "1e8"),
507+
(1.1e8, "1.1e8"),
508+
]
509+
503510
@pytest.mark.parametrize('unicode_minus, result',
504511
[(True, "\N{MINUS SIGN}1"), (False, "-1")])
505512
def test_unicode_minus(self, unicode_minus, result):
@@ -561,6 +568,12 @@ def test_scilimits(self, sci_type, scilimits, lim, orderOfMag, fewticks):
561568
tmp_form.set_locs(ax.yaxis.get_majorticklocs())
562569
assert orderOfMag == tmp_form.orderOfMagnitude
563570

571+
@pytest.mark.parametrize('value, expected', format_data)
572+
def test_format_data(self, value, expected):
573+
mpl.rcParams['axes.unicode_minus'] = False
574+
sf = mticker.ScalarFormatter()
575+
assert sf.format_data(value) == expected
576+
564577
@pytest.mark.parametrize('data, expected', cursor_data)
565578
def test_cursor_precision(self, data, expected):
566579
fig, ax = plt.subplots()

lib/matplotlib/ticker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def format_data(self, value):
664664
s = round(value / 10**e, 10)
665665
exponent = self._format_maybe_minus_and_locale("%d", e)
666666
significand = self._format_maybe_minus_and_locale(
667-
"%d" if s % 1 == 0 else "%1.10f", s)
667+
"%d" if s % 1 == 0 else "%1.10g", s)
668668
if e == 0:
669669
return significand
670670
elif self._useMathText or self._usetex:

0 commit comments

Comments
 (0)