24
24
# the image namespace:
25
25
from matplotlib ._image import *
26
26
27
- from matplotlib .transforms import BboxBase
27
+ from matplotlib .transforms import BboxBase , Bbox
28
28
import matplotlib .transforms as mtransforms
29
29
30
30
class _AxesImageBase (martist .Artist , cm .ScalarMappable ):
@@ -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 , noslice = False ):
138
+ def _get_unsampled_image (self , A , image_extents , viewlim ):
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, noslice=False):
150
150
sx = dxintv / viewlim .width
151
151
sy = dyintv / viewlim .height
152
152
numrows , numcols = A .shape [:2 ]
153
- if noslice is False and sx > 2 :
153
+ if 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, noslice=False):
164
164
else :
165
165
xslice = slice (0 , numcols )
166
166
167
- if noslice is False and sy > 2 :
167
+ if 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
@@ -248,9 +248,57 @@ def _draw_unsampled_image(self, renderer, gc):
248
248
"""
249
249
250
250
251
+ trans = self .get_transform () #axes.transData
252
+
253
+ # convert the coordinates to the intermediate coordinate (ic).
254
+ # The transformation from the ic to the canvas is a pure
255
+ # affine transfor.
256
+
257
+ # A straight-forward way is to use the non-affine part of the
258
+ # original transform for conversion to the ic.
259
+
260
+ # firs, convert the image extent to the ic
261
+ x_llc , x_trc , y_llc , y_trc = self .get_extent ()
262
+
263
+ xy = trans .transform_non_affine (np .array ([(x_llc , y_llc ),
264
+ (x_trc , y_trc )]))
265
+
266
+ _xx1 , _yy1 = xy [0 ]
267
+ _xx2 , _yy2 = xy [1 ]
268
+
269
+ extent_in_ic = _xx1 , _xx2 , _yy1 , _yy2
270
+
271
+ # define trans_ic_to_canvas : unless _image_skew_coordinate is
272
+ # set, it is simply a affine part of the original transform.
273
+ if self ._image_skew_coordinate :
274
+ # skew the image when required.
275
+ x_lrc , y_lrc = self ._image_skew_coordinate
276
+ xy2 = trans .transform_non_affine (np .array ([(x_lrc , y_lrc )]))
277
+ _xx3 , _yy3 = xy2 [0 ]
278
+
279
+ tr_rotate_skew = self ._get_rotate_and_skew_transform (_xx1 , _yy1 ,
280
+ _xx2 , _yy2 ,
281
+ _xx3 , _yy3 )
282
+ trans_ic_to_canvas = tr_rotate_skew + trans .get_affine ()
283
+ else :
284
+ trans_ic_to_canvas = trans .get_affine ()
285
+
286
+ # Now, viewLim in the ic. It can be roated and can be
287
+ # skewed. Make it big enough.
288
+ x1 , y1 , x2 , y2 = self .axes .bbox .extents
289
+ trans_canvas_to_ic = trans_ic_to_canvas .inverted ()
290
+ xy_ = trans_canvas_to_ic .transform (np .array ([(x1 , y1 ),
291
+ (x2 , y1 ),
292
+ (x2 , y2 ),
293
+ (x1 , y2 )]))
294
+ x1_ , x2_ = min (xy_ [:,0 ]), max (xy_ [:,0 ])
295
+ y1_ , y2_ = min (xy_ [:,1 ]), max (xy_ [:,1 ])
296
+ viewLim_in_ic = Bbox .from_extents (x1_ , y1_ , x2_ , y2_ )
297
+
298
+
299
+ # get the image, sliced if necessary. This is done in the ic.
251
300
im , xmin , ymin , dxintv , dyintv , sx , sy = \
252
- self ._get_unsampled_image (self ._A , self .get_extent (),
253
- self .axes .viewLim , noslice = True )
301
+ self ._get_unsampled_image (self ._A , extent_in_ic , viewLim_in_ic )
254
302
255
303
if im is None : return # I'm not if this check is required. -JJL
256
304
@@ -262,33 +310,14 @@ def _draw_unsampled_image(self, renderer, gc):
262
310
im .reset_matrix ()
263
311
numrows , numcols = im .get_size ()
264
312
265
- im .resize (numcols , numrows ) # just to create im.bufOut that is required by backends. There may be better solution -JJL
313
+ im .resize (numcols , numrows ) # just to create im.bufOut that
314
+ # is required by backends. There
315
+ # may be better solution -JJL
266
316
267
317
im ._url = self .get_url ()
268
318
269
- trans = self .get_transform () #axes.transData
270
- xy = trans .transform_non_affine (np .array ([(xmin , ymin ),
271
- (xmin + dxintv , ymin + dyintv )]))
272
- xx1 , yy1 = xy [0 ]
273
- xx2 , yy2 = xy [1 ]
274
-
275
- if self ._image_skew_coordinate :
276
- # skew the image when required.
277
- x_llc , x_trc , y_llc , y_trc = self .get_extent ()
278
- x_lrc , y_lrc = self ._image_skew_coordinate
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 )
287
- tr = tr_rotate_skew + trans .get_affine ()
288
- else :
289
- tr = trans .get_affine ()
290
-
291
- renderer .draw_image (gc , xx1 , yy1 , im , xx2 - xx1 , yy2 - yy1 , tr )
319
+ renderer .draw_image (gc , xmin , ymin , im , dxintv , dyintv ,
320
+ trans_ic_to_canvas )
292
321
293
322
294
323
def _check_unsampled_image (self , renderer ):
0 commit comments