@@ -637,6 +637,7 @@ def test_basic(self, labelOnlyBase, base, exponent, locs, positions,
637637 formatter .axis = FakeAxis (1 , base ** exponent )
638638 vals = base ** locs
639639 labels = [formatter (x , pos ) for (x , pos ) in zip (vals , positions )]
640+ expected = [label .replace ('-' , '\N{Minus Sign} ' ) for label in expected ]
640641 assert labels == expected
641642
642643 def test_blank (self ):
@@ -662,7 +663,7 @@ class TestLogFormatterMathtext:
662663 @pytest .mark .parametrize ('min_exponent, value, expected' , test_data )
663664 def test_min_exponent (self , min_exponent , value , expected ):
664665 with mpl .rc_context ({'axes.formatter.min_exponent' : min_exponent }):
665- assert self .fmt (value ) == expected
666+ assert self .fmt (value ) == expected . replace ( '-' , ' \N{Minus Sign} ' )
666667
667668
668669class TestLogFormatterSciNotation :
@@ -691,7 +692,7 @@ def test_basic(self, base, value, expected):
691692 formatter = mticker .LogFormatterSciNotation (base = base )
692693 formatter .sublabel = {1 , 2 , 5 , 1.2 }
693694 with mpl .rc_context ({'text.usetex' : False }):
694- assert formatter (value ) == expected
695+ assert formatter (value ) == expected . replace ( '-' , ' \N{Minus Sign} ' )
695696
696697
697698class TestLogFormatter :
@@ -907,19 +908,21 @@ def logit_deformatter(string):
907908 float 1.41e-4, as '0.5' or as r'$\mathdefault{\frac{1}{2}}$' in float
908909 0.5,
909910 """
911+ # Can inline the Unicode escapes to the raw strings in Python 3.8+
910912 match = re .match (
911913 r"[^\d]*"
912- r"(?P<comp>1- )?"
914+ r"(?P<comp>1" "[- \N{Minus Sign} ]" r" )?"
913915 r"(?P<mant>\d*\.?\d*)?"
914916 r"(?:\\cdot)?"
915- r"(?:10\^\{(?P<expo>- ?\d*)})?"
917+ r"(?:10\^\{(?P<expo>" "[- \N{Minus Sign} ]" r" ?\d*)})?"
916918 r"[^\d]*$" ,
917919 string ,
918920 )
919921 if match :
920922 comp = match ["comp" ] is not None
921923 mantissa = float (match ["mant" ]) if match ["mant" ] else 1
922- expo = int (match ["expo" ]) if match ["expo" ] is not None else 0
924+ expo = (int (match ["expo" ].replace ("\N{Minus Sign} " , "-" ))
925+ if match ["expo" ] is not None else 0 )
923926 value = mantissa * 10 ** expo
924927 if match ["mant" ] or match ["expo" ] is not None :
925928 if comp :
@@ -1044,8 +1047,8 @@ def test_use_overline(self):
10441047 Test the parameter use_overline
10451048 """
10461049 x = 1 - 1e-2
1047- fx1 = r "$\mathdefault{1- 10^{- 2}}$"
1048- fx2 = r "$\mathdefault{\overline{10^{- 2}}}$"
1050+ fx1 = "$\\ mathdefault{1\N{Minus Sign} 10^{\N{Minus Sign} 2}}$"
1051+ fx2 = "$\\ mathdefault{\\ overline{10^{\N{Minus Sign} 2}}}$"
10491052 form = mticker .LogitFormatter (use_overline = False )
10501053 assert form (x ) == fx1
10511054 form .use_overline (True )
0 commit comments