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

Commit93cfbcf

Browse files
committed
ticker: Improve and rename EngFormatter offset test
1 parent1074bb8 commit93cfbcf

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

‎lib/matplotlib/tests/test_ticker.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,19 +1594,47 @@ def test_engformatter_usetex_useMathText():
15941594
assertx_tick_label_text== ['$0$','$500$','$1$ k']
15951595

15961596

1597-
deftest_engformatter_useOffset():
1597+
@pytest.mark.parametrize(
1598+
'oom_center, oom_noise', [
1599+
(15,6),
1600+
(12,3),
1601+
(9,3),
1602+
(9,6),
1603+
(0,-6),
1604+
# Going to lower orders of magnitudes will make this test fail due to
1605+
# floating points approximated as zero. Putting 12 and above oom difference
1606+
# between center and the noise will also fail, due to ticks give different
1607+
# unit prefixes
1608+
]
1609+
)
1610+
deftest_engformatter_offset(oom_center,oom_noise):
1611+
UNIT="eV"
1612+
# Intentionally picking also negative numbers
1613+
r=range(-2,9)
15981614
fig,ax=plt.subplots()
1599-
data_offset=10000000
1600-
ydata=range(data_offset,data_offset+5)
1615+
data_offset=10**oom_center
1616+
ydata=data_offset+np.array(r,dtype=float)*10**oom_noise
16011617
ax.plot(ydata)
16021618
ax.set_yticks(ydata)
1603-
ax.yaxis.set_major_formatter(mticker.EngFormatter(useOffset=True,unit="Hz"))
1619+
formatter=mticker.EngFormatter(useOffset=True,unit=UNIT)
1620+
ax.yaxis.set_major_formatter(formatter)
16041621
fig.canvas.draw()
1605-
y_tick_label_text= [labl.get_text()forlablinax.get_yticklabels()]
1606-
offset=ax.yaxis.get_major_formatter().get_offset()
1607-
expectedTicks=list(map("{} Hz".format,np.array(ydata)-data_offset))
1608-
asserty_tick_label_text==expectedTicks
1609-
assert"+10 MHz"==offset
1622+
ticksGot= [labl.get_text()forlablinax.get_yticklabels()]
1623+
ticksExpected=list(map(
1624+
# Fix negative number's - sign in case unicode is used
1625+
lambdan:formatter.fix_minus(str(n))+" "+ (
1626+
# zero is zero, no matter what is the oom
1627+
formatter.ENG_PREFIXES[oom_noise]ifn!=0else""
1628+
)+UNIT,
1629+
r
1630+
))
1631+
offsetGot=ax.yaxis.get_major_formatter().get_offset()
1632+
offsetExpected="+1 {}{}".format(
1633+
formatter.ENG_PREFIXES[oom_center],
1634+
UNIT
1635+
)
1636+
assertticksGot==ticksExpected
1637+
assertoffsetExpected==offsetGot
16101638

16111639

16121640
classTestPercentFormatter:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp