@@ -135,7 +135,7 @@ def make_image(self, magnification=1.0):
135
135
raise RuntimeError ('The make_image method must be overridden.' )
136
136
137
137
138
- def _get_unsampled_image (self , A , image_extents , viewlim ):
138
+ def _get_unsampled_image (self , A , image_extents , viewlim , noslice = False ):
139
139
"""
140
140
convert numpy array A with given extents ([x1, x2, y1, y2] in
141
141
data coordinate) into the Image, given the vielim (should be a
@@ -150,7 +150,7 @@ def _get_unsampled_image(self, A, image_extents, viewlim):
150
150
sx = dxintv / viewlim .width
151
151
sy = dyintv / viewlim .height
152
152
numrows , numcols = A .shape [:2 ]
153
- if sx > 2 :
153
+ if noslice is False and sx > 2 :
154
154
x0 = (viewlim .x0 - xmin )/ dxintv * numcols
155
155
ix0 = max (0 , int (x0 - self ._filterrad ))
156
156
x1 = (viewlim .x1 - xmin )/ dxintv * numcols
@@ -164,7 +164,7 @@ def _get_unsampled_image(self, A, image_extents, viewlim):
164
164
else :
165
165
xslice = slice (0 , numcols )
166
166
167
- if sy > 2 :
167
+ if noslice is False and sy > 2 :
168
168
y0 = (viewlim .y0 - ymin )/ dyintv * numrows
169
169
iy0 = max (0 , int (y0 - self ._filterrad ))
170
170
y1 = (viewlim .y1 - ymin )/ dyintv * numrows
@@ -246,8 +246,11 @@ def _draw_unsampled_image(self, renderer, gc):
246
246
draw unsampled image. The renderer should support a draw_image method
247
247
with scale parameter.
248
248
"""
249
+
250
+
249
251
im , xmin , ymin , dxintv , dyintv , sx , sy = \
250
- self ._get_unsampled_image (self ._A , self .get_extent (), self .axes .viewLim )
252
+ self ._get_unsampled_image (self ._A , self .get_extent (),
253
+ self .axes .viewLim , noslice = True )
251
254
252
255
if im is None : return # I'm not if this check is required. -JJL
253
256
@@ -264,18 +267,23 @@ def _draw_unsampled_image(self, renderer, gc):
264
267
im ._url = self .get_url ()
265
268
266
269
trans = self .get_transform () #axes.transData
267
- xy = trans .transform_non_affine ([(xmin , ymin ),
268
- (xmin + dxintv , ymin + dyintv )])
270
+ xy = trans .transform_non_affine (np . array ( [(xmin , ymin ),
271
+ (xmin + dxintv , ymin + dyintv )]) )
269
272
xx1 , yy1 = xy [0 ]
270
273
xx2 , yy2 = xy [1 ]
271
274
272
275
if self ._image_skew_coordinate :
273
276
# skew the image when required.
277
+ x_llc , x_trc , y_llc , y_trc = self .get_extent ()
274
278
x_lrc , y_lrc = self ._image_skew_coordinate
275
- xy = trans .transform_non_affine ([(x_lrc , y_lrc )])
276
- xx3 , yy3 = xy [0 ]
277
-
278
- tr_rotate_skew = self ._get_rotate_and_skew_transform (xx1 , yy1 , xx2 , yy2 , xx3 , yy3 )
279
+ xy = trans .transform_non_affine (np .array ([(x_llc , y_llc ),
280
+ (x_trc , y_trc ),
281
+ (x_lrc , y_lrc )]))
282
+ _xx1 , _yy1 = xy [0 ]
283
+ _xx2 , _yy2 = xy [1 ]
284
+ _xx3 , _yy3 = xy [2 ]
285
+
286
+ tr_rotate_skew = self ._get_rotate_and_skew_transform (_xx1 , _yy1 , _xx2 , _yy2 , _xx3 , _yy3 )
279
287
tr = tr_rotate_skew + trans .get_affine ()
280
288
else :
281
289
tr = trans .get_affine ()
@@ -509,8 +517,21 @@ def make_image(self, magnification=1.0):
509
517
if self ._A is None :
510
518
raise RuntimeError ('You must first set the image array or the image attribute' )
511
519
520
+ # image is created in the canvas coordinate.
521
+ x1 , x2 , y1 , y2 = self .get_extent ()
522
+ trans = self .get_transform ()
523
+ xy = trans .transform (np .array ([(x1 , y1 ),
524
+ (x2 , y2 ),
525
+ ]))
526
+ _x1 , _y1 = xy [0 ]
527
+ _x2 , _y2 = xy [1 ]
528
+
529
+ transformed_viewLim = mtransforms .TransformedBbox (self .axes .viewLim ,
530
+ trans )
531
+
512
532
im , xmin , ymin , dxintv , dyintv , sx , sy = \
513
- self ._get_unsampled_image (self ._A , self .get_extent (), self .axes .viewLim )
533
+ self ._get_unsampled_image (self ._A , [_x1 , _x2 , _y1 , _y2 ],
534
+ transformed_viewLim )
514
535
515
536
fc = self .axes .patch .get_facecolor ()
516
537
bg = mcolors .colorConverter .to_rgba (fc , 0 )
@@ -526,8 +547,8 @@ def make_image(self, magnification=1.0):
526
547
im .set_resample (self ._resample )
527
548
528
549
# the viewport translation
529
- tx = (xmin - self . axes . viewLim .x0 )/ dxintv * numcols
530
- ty = (ymin - self . axes . viewLim .y0 )/ dyintv * numrows
550
+ tx = (xmin - transformed_viewLim .x0 )/ dxintv * numcols
551
+ ty = (ymin - transformed_viewLim .y0 )/ dyintv * numrows
531
552
532
553
l , b , r , t = self .axes .bbox .extents
533
554
widthDisplay = (round (r * magnification ) + 0.5 ) - (round (l * magnification ) - 0.5 )
0 commit comments