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

Commitd931283

Browse files
committed
Add more transforms to affine image transform demo
1 parent4bcb38f commitd931283

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

‎examples/api/demo_affine_image.py‎

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""
2-
For the backends thatsupports draw_image with optional affine
2+
For the backends thatsupport draw_image with optional affine
33
transform (e.g., agg, ps backend), the image of the output should
4-
have its boundarymatches thered rectangles.
4+
have its boundarymatch thedashed yellow rectangle.
55
"""
66

77
importnumpyasnp
8-
importmatplotlib.cmascm
98
importmatplotlib.mlabasmlab
109
importmatplotlib.pyplotasplt
1110
importmatplotlib.transformsasmtransforms
@@ -21,25 +20,37 @@ def get_image():
2120
returnZ
2221

2322

24-
if1:
23+
defdo_plot(ax,Z,transform):
24+
im=ax.imshow(Z,interpolation='none',
25+
origin='lower',
26+
extent=[-2,4,-3,2],clip_on=True)
2527

26-
# image rotation
28+
trans_data=transform+ax.transData
29+
im.set_transform(trans_data)
2730

28-
fig,ax1=plt.subplots(1,1)
29-
Z=get_image()
30-
im1=ax1.imshow(Z,interpolation='none',
31-
origin='lower',
32-
extent=[-2,4,-3,2],clip_on=True)
31+
# display intended extent of the image
32+
x1,x2,y1,y2=im.get_extent()
33+
ax.plot([x1,x2,x2,x1,x1], [y1,y1,y2,y2,y1],"y--",
34+
transform=trans_data)
35+
ax.set_xlim(-5,5)
36+
ax.set_ylim(-4,4)
3337

34-
trans_data2=mtransforms.Affine2D().rotate_deg(30)+ax1.transData
35-
im1.set_transform(trans_data2)
3638

37-
# display intended extent of the image
38-
x1,x2,y1,y2=im1.get_extent()
39-
x3,y3=x2,y1
39+
# prepare image and figure
40+
fig, ((ax1,ax2), (ax3,ax4))=plt.subplots(2,2)
41+
Z=get_image()
42+
43+
# image rotation
44+
do_plot(ax1,Z,mtransforms.Affine2D().rotate_deg(30))
45+
46+
# image skew
47+
do_plot(ax2,Z,mtransforms.Affine2D().skew_deg(30,15))
48+
49+
# scale and reflection
50+
do_plot(ax3,Z,mtransforms.Affine2D().scale(-1,.5))
4051

41-
ax1.plot([x1,x2,x2,x1,x1], [y1,y1,y2,y2,y1],"--",
42-
transform=trans_data2)
52+
# everything and a translation
53+
do_plot(ax4,Z,mtransforms.Affine2D().
54+
rotate_deg(30).skew_deg(30,15).scale(-1,.5).translate(.5,-1))
4355

44-
ax1.set_xlim(-3,5)
45-
ax1.set_ylim(-4,4)
56+
plt.show()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp