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

Commit398be5f

Browse files
committed
Add test to check for consistency in scaling images to axes edges
1 parentbebb263 commit398be5f

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

‎lib/matplotlib/tests/test_image.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,17 @@ def test__resample_valid_output():
16411641
resample(np.zeros((9,9)),out)
16421642

16431643

1644+
@pytest.fixture
1645+
defnonaffine_identity():
1646+
classNonAffineIdentityTransform(Transform):
1647+
input_dims=2
1648+
output_dims=2
1649+
1650+
definverted(self):
1651+
returnself
1652+
returnNonAffineIdentityTransform()
1653+
1654+
16441655
@pytest.mark.parametrize("data, interpolation, expected",
16451656
[(np.array([[0.1,0.3,0.2]]),mimage.NEAREST,
16461657
np.array([[0.1,0.1,0.1,0.3,0.3,0.3,0.3,0.2,0.2,0.2]])),
@@ -1649,7 +1660,7 @@ def test__resample_valid_output():
16491660
0.28476562,0.2546875,0.22460938,0.20002441,0.20002441]])),
16501661
]
16511662
)
1652-
deftest_resample_nonaffine(data,interpolation,expected):
1663+
deftest_resample_nonaffine(data,interpolation,expected,nonaffine_identity):
16531664
# Test that equivalent affine and nonaffine transforms resample the same
16541665

16551666
# Create a simple affine transform for scaling the input array
@@ -1661,20 +1672,36 @@ def test_resample_nonaffine(data, interpolation, expected):
16611672

16621673
# Create a nonaffine version of the same transform
16631674
# by compositing with a nonaffine identity transform
1664-
classNonAffineIdentityTransform(Transform):
1665-
input_dims=2
1666-
output_dims=2
1667-
1668-
definverted(self):
1669-
returnself
1670-
nonaffine_transform=NonAffineIdentityTransform()+affine_transform
1675+
nonaffine_transform=nonaffine_identity+affine_transform
16711676

16721677
nonaffine_result=np.empty_like(expected)
16731678
mimage.resample(data,nonaffine_result,nonaffine_transform,
16741679
interpolation=interpolation)
16751680
assert_allclose(nonaffine_result,expected,atol=5e-3)
16761681

16771682

1683+
@check_figures_equal()
1684+
deftest_nonaffine_scaling_to_axes_edges(fig_test,fig_ref,nonaffine_identity):
1685+
# Test that plotting an image with equivalent affine and nonaffine
1686+
# transforms is scaled the same to the axes edges
1687+
data=np.arange(16).reshape((4,4))%3
1688+
1689+
# Specifically choose an axes bbox that has a fractional pixel
1690+
1691+
fig_test.set_size_inches(5,5)
1692+
fig_test.set_dpi(100)
1693+
ax=fig_test.subplots()
1694+
ax.set_position([0.2,0.2,300.5/500,300.5/500])
1695+
ax.imshow(data,interpolation='nearest',
1696+
transform=nonaffine_identity+ax.transData)
1697+
1698+
fig_ref.set_size_inches(5,5)
1699+
fig_ref.set_dpi(100)
1700+
ax=fig_ref.subplots()
1701+
ax.set_position([0.2,0.2,300.5/500,300.5/500])
1702+
ax.imshow(data,interpolation='nearest')
1703+
1704+
16781705
deftest_axesimage_get_shape():
16791706
# generate dummy image to test get_shape method
16801707
ax=plt.gca()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp