Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit52003e4

Browse files
committed
Ensure log formatters use Unicode minus
Fixes#21540
1 parent3d91b3f commit52003e4

File tree

7 files changed

+1228
-1195
lines changed

7 files changed

+1228
-1195
lines changed
Binary file not shown.

‎lib/matplotlib/tests/baseline_images/test_axes/errorbar_mixed.svg

Lines changed: 1208 additions & 1182 deletions
Loading

‎lib/matplotlib/tests/test_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,9 @@ def test_pyplot_axes():
25452545

25462546
@image_comparison(['log_scales'])
25472547
deftest_log_scales():
2548+
# Remove this if regenerating the image.
2549+
plt.rcParams['axes.unicode_minus']=False
2550+
25482551
fig,ax=plt.subplots()
25492552
ax.plot(np.log(np.linspace(0.1,100)))
25502553
ax.set_yscale('log',base=5.5)

‎lib/matplotlib/tests/test_colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def test_colorbar_format(fmt):
577577
im.set_norm(LogNorm(vmin=0.1,vmax=10))
578578
fig.canvas.draw()
579579
assert (cbar.ax.yaxis.get_ticklabels()[0].get_text()==
580-
r'$\mathdefault{10^{-2}}$')
580+
'$\\mathdefault{10^{\N{Minus Sign}2}}$')
581581

582582

583583
deftest_colorbar_scale_reset():

‎lib/matplotlib/tests/test_ticker.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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)inzip(vals,positions)]
640+
expected= [label.replace('-','\N{Minus Sign}')forlabelinexpected]
640641
assertlabels==expected
641642

642643
deftest_blank(self):
@@ -662,7 +663,7 @@ class TestLogFormatterMathtext:
662663
@pytest.mark.parametrize('min_exponent, value, expected',test_data)
663664
deftest_min_exponent(self,min_exponent,value,expected):
664665
withmpl.rc_context({'axes.formatter.min_exponent':min_exponent}):
665-
assertself.fmt(value)==expected
666+
assertself.fmt(value)==expected.replace('-','\N{Minus Sign}')
666667

667668

668669
classTestLogFormatterSciNotation:
@@ -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
withmpl.rc_context({'text.usetex':False}):
694-
assertformatter(value)==expected
695+
assertformatter(value)==expected.replace('-','\N{Minus Sign}')
695696

696697

697698
classTestLogFormatter:
@@ -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
ifmatch:
920922
comp=match["comp"]isnotNone
921923
mantissa=float(match["mant"])ifmatch["mant"]else1
922-
expo=int(match["expo"])ifmatch["expo"]isnotNoneelse0
924+
expo= (int(match["expo"].replace("\N{Minus Sign}","-"))
925+
ifmatch["expo"]isnotNoneelse0)
923926
value=mantissa*10**expo
924927
ifmatch["mant"]ormatch["expo"]isnotNone:
925928
ifcomp:
@@ -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
assertform(x)==fx1
10511054
form.use_overline(True)

‎lib/matplotlib/ticker.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ def __call__(self, x, pos=None):
10001000
vmin,vmax=self.axis.get_view_interval()
10011001
vmin,vmax=mtransforms.nonsingular(vmin,vmax,expander=0.05)
10021002
s=self._num_to_string(x,vmin,vmax)
1003-
returns
1003+
returnself.fix_minus(s)
10041004

10051005
defformat_data(self,value):
10061006
withcbook._setattr_cm(self,labelOnlyBase=False):
@@ -1090,11 +1090,12 @@ def __call__(self, x, pos=None):
10901090
base='%s'%b
10911091

10921092
ifabs(fx)<min_exp:
1093-
returnr'$\mathdefault{%s%g}$'% (sign_string,x)
1093+
s=r'$\mathdefault{%s%g}$'% (sign_string,x)
10941094
elifnotis_x_decade:
1095-
returnself._non_decade_format(sign_string,base,fx,usetex)
1095+
s=self._non_decade_format(sign_string,base,fx,usetex)
10961096
else:
1097-
returnr'$\mathdefault{%s%s^{%d}}$'% (sign_string,base,fx)
1097+
s=r'$\mathdefault{%s%s^{%d}}$'% (sign_string,base,fx)
1098+
returnself.fix_minus(s)
10981099

10991100

11001101
classLogFormatterSciNotation(LogFormatterMathtext):
@@ -1296,7 +1297,7 @@ def __call__(self, x, pos=None):
12961297
s=self._one_minus(self._format_value(1-x,1-self.locs))
12971298
else:
12981299
s=self._format_value(x,self.locs,sci_notation=False)
1299-
returnr"$\mathdefault{%s}$"%s
1300+
returnr"$\mathdefault{%s}$"%self.fix_minus(s)
13001301

13011302
defformat_data_short(self,value):
13021303
# docstring inherited

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp