1
1
"""
2
- For the backends that supports draw_image with optional affine
2
+ For the backends that support draw_image with optional affine
3
3
transform (e.g., agg, ps backend), the image of the output should
4
- have its boundary matches the red rectangles .
4
+ have its boundary match the dashed yellow rectangle .
5
5
"""
6
6
7
7
import numpy as np
8
- import matplotlib .cm as cm
9
8
import matplotlib .mlab as mlab
10
9
import matplotlib .pyplot as plt
11
10
import matplotlib .transforms as mtransforms
@@ -21,25 +20,37 @@ def get_image():
21
20
return Z
22
21
23
22
24
- if 1 :
23
+ def do_plot (ax , Z , transform ):
24
+ im = ax .imshow (Z , interpolation = 'none' ,
25
+ origin = 'lower' ,
26
+ extent = [- 2 , 4 , - 3 , 2 ], clip_on = True )
25
27
26
- # image rotation
28
+ trans_data = transform + ax .transData
29
+ im .set_transform (trans_data )
30
+
31
+ # display intended extent of the image
32
+ x1 , x2 , y1 , y2 = im .get_extent ()
33
+ x3 , y3 = x2 , y1
34
+
35
+ ax .plot ([x1 , x2 , x2 , x1 , x1 ], [y1 , y1 , y2 , y2 , y1 ], "y--" ,
36
+ transform = trans_data )
37
+ ax .set_xlim (- 5 , 5 )
38
+ ax .set_ylim (- 4 , 4 )
27
39
28
- fig , ax1 = plt .subplots (1 , 1 )
40
+
41
+ if 1 :
42
+ fig , ((ax1 , ax2 ), (ax3 , ax4 )) = plt .subplots (2 , 2 )
29
43
Z = get_image ()
30
- im1 = ax1 .imshow (Z , interpolation = 'none' ,
31
- origin = 'lower' ,
32
- extent = [- 2 , 4 , - 3 , 2 ], clip_on = True )
33
44
34
- trans_data2 = mtransforms . Affine2D (). rotate_deg ( 30 ) + ax1 . transData
35
- im1 . set_transform ( trans_data2 )
45
+ # image rotation
46
+ do_plot ( ax1 , Z , mtransforms . Affine2D (). rotate_deg ( 30 ) )
36
47
37
- # display intended extent of the image
38
- x1 , x2 , y1 , y2 = im1 .get_extent ()
39
- x3 , y3 = x2 , y1
48
+ # image skew
49
+ do_plot (ax2 , Z , mtransforms .Affine2D ().skew_deg (30 , 15 ))
40
50
41
- ax1 . plot ([ x1 , x2 , x2 , x1 , x1 ], [ y1 , y1 , y2 , y2 , y1 ], "--" ,
42
- transform = trans_data2 )
51
+ # scale and reflection
52
+ do_plot ( ax3 , Z , mtransforms . Affine2D (). scale ( - 1 , .5 ) )
43
53
44
- ax1 .set_xlim (- 3 , 5 )
45
- ax1 .set_ylim (- 4 , 4 )
54
+ # everything
55
+ do_plot (ax4 , Z , mtransforms .Affine2D ().
56
+ rotate_deg (30 ).skew_deg (30 , 15 ).scale (- 1 , .5 ))
0 commit comments