Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f42007e

Browse filesBrowse files
pharshalpMeeseeksDev[bot]
authored andcommitted
Backport PR #13477: FIX: make EngFormatter respect axes.unicode_minus rcParam
1 parent 93ee6aa commit f42007e
Copy full SHA for f42007e

File tree

Expand file treeCollapse file tree

2 files changed

+46
-24
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+46
-24
lines changed

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+40-24Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -694,33 +694,48 @@ def test_basic(self, format, input, expected):
694694

695695

696696
class TestEngFormatter(object):
697-
# (input, expected) where ''expected'' corresponds to the outputs
698-
# respectively returned when (places=None, places=0, places=2)
697+
# (unicode_minus, input, expected) where ''expected'' corresponds to the
698+
# outputs respectively returned when (places=None, places=0, places=2)
699+
# unicode_minus is a boolean value for the rcParam['axes.unicode_minus']
699700
raw_format_data = [
700-
(-1234.56789, ('-1.23457 k', '-1 k', '-1.23 k')),
701-
(-1.23456789, ('-1.23457', '-1', '-1.23')),
702-
(-0.123456789, ('-123.457 m', '-123 m', '-123.46 m')),
703-
(-0.00123456789, ('-1.23457 m', '-1 m', '-1.23 m')),
704-
(-0.0, ('0', '0', '0.00')),
705-
(-0, ('0', '0', '0.00')),
706-
(0, ('0', '0', '0.00')),
707-
(1.23456789e-6, ('1.23457 µ', '1 µ', '1.23 µ')),
708-
(0.123456789, ('123.457 m', '123 m', '123.46 m')),
709-
(0.1, ('100 m', '100 m', '100.00 m')),
710-
(1, ('1', '1', '1.00')),
711-
(1.23456789, ('1.23457', '1', '1.23')),
712-
(999.9, ('999.9', '1 k', '999.90')), # places=0: corner-case rounding
713-
(999.9999, ('1 k', '1 k', '1.00 k')), # corner-case rounding for all
714-
(-999.9999, ('-1 k', '-1 k', '-1.00 k')), # negative corner-case
715-
(1000, ('1 k', '1 k', '1.00 k')),
716-
(1001, ('1.001 k', '1 k', '1.00 k')),
717-
(100001, ('100.001 k', '100 k', '100.00 k')),
718-
(987654.321, ('987.654 k', '988 k', '987.65 k')),
719-
(1.23e27, ('1230 Y', '1230 Y', '1230.00 Y')) # OoR value (> 1000 Y)
701+
(False, -1234.56789, ('-1.23457 k', '-1 k', '-1.23 k')),
702+
(True, -1234.56789, ('\N{MINUS SIGN}1.23457 k', '\N{MINUS SIGN}1 k',
703+
'\N{MINUS SIGN}1.23 k')),
704+
(False, -1.23456789, ('-1.23457', '-1', '-1.23')),
705+
(True, -1.23456789, ('\N{MINUS SIGN}1.23457', '\N{MINUS SIGN}1',
706+
'\N{MINUS SIGN}1.23')),
707+
(False, -0.123456789, ('-123.457 m', '-123 m', '-123.46 m')),
708+
(True, -0.123456789, ('\N{MINUS SIGN}123.457 m', '\N{MINUS SIGN}123 m',
709+
'\N{MINUS SIGN}123.46 m')),
710+
(False, -0.00123456789, ('-1.23457 m', '-1 m', '-1.23 m')),
711+
(True, -0.00123456789, ('\N{MINUS SIGN}1.23457 m', '\N{MINUS SIGN}1 m',
712+
'\N{MINUS SIGN}1.23 m')),
713+
(True, -0.0, ('0', '0', '0.00')),
714+
(True, -0, ('0', '0', '0.00')),
715+
(True, 0, ('0', '0', '0.00')),
716+
(True, 1.23456789e-6, ('1.23457 µ', '1 µ', '1.23 µ')),
717+
(True, 0.123456789, ('123.457 m', '123 m', '123.46 m')),
718+
(True, 0.1, ('100 m', '100 m', '100.00 m')),
719+
(True, 1, ('1', '1', '1.00')),
720+
(True, 1.23456789, ('1.23457', '1', '1.23')),
721+
# places=0: corner-case rounding
722+
(True, 999.9, ('999.9', '1 k', '999.90')),
723+
# corner-case rounding for all
724+
(True, 999.9999, ('1 k', '1 k', '1.00 k')),
725+
# negative corner-case
726+
(False, -999.9999, ('-1 k', '-1 k', '-1.00 k')),
727+
(True, -999.9999, ('\N{MINUS SIGN}1 k', '\N{MINUS SIGN}1 k',
728+
'\N{MINUS SIGN}1.00 k')),
729+
(True, 1000, ('1 k', '1 k', '1.00 k')),
730+
(True, 1001, ('1.001 k', '1 k', '1.00 k')),
731+
(True, 100001, ('100.001 k', '100 k', '100.00 k')),
732+
(True, 987654.321, ('987.654 k', '988 k', '987.65 k')),
733+
# OoR value (> 1000 Y)
734+
(True, 1.23e27, ('1230 Y', '1230 Y', '1230.00 Y'))
720735
]
721736

722-
@pytest.mark.parametrize('input, expected', raw_format_data)
723-
def test_params(self, input, expected):
737+
@pytest.mark.parametrize('unicode_minus, input, expected', raw_format_data)
738+
def test_params(self, unicode_minus, input, expected):
724739
"""
725740
Test the formatting of EngFormatter for various values of the 'places'
726741
argument, in several cases:
@@ -731,6 +746,7 @@ def test_params(self, input, expected):
731746
Note that cases 2. and 3. are looped over several separator strings.
732747
"""
733748

749+
plt.rcParams['axes.unicode_minus'] = unicode_minus
734750
UNIT = 's' # seconds
735751
DIGITS = '0123456789' # %timeit showed 10-20% faster search than set
736752

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,12 @@ def set_useMathText(self, val):
12721272

12731273
useMathText = property(fget=get_useMathText, fset=set_useMathText)
12741274

1275+
def fix_minus(self, s):
1276+
"""
1277+
Replace hyphens with a unicode minus.
1278+
"""
1279+
return ScalarFormatter.fix_minus(self, s)
1280+
12751281
def __call__(self, x, pos=None):
12761282
s = "%s%s" % (self.format_eng(x), self.unit)
12771283
# Remove the trailing separator when there is neither prefix nor unit

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.