@@ -251,7 +251,11 @@ def get_size(self):
251251 if self ._A is None :
252252 raise RuntimeError ('You must first set the image array' )
253253
254- return self ._A .shape [:2 ]
254+ if isinstance (self .norm , mcolors .BivariateNorm ):
255+ imshape = self ._A .shape [1 :]
256+ else :
257+ imshape = self ._A .shape [:2 ]
258+ return imshape
255259
256260 def set_alpha (self , alpha ):
257261 """
@@ -298,6 +302,12 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
298302 `trans` is the affine transformation from the image to pixel
299303 space.
300304 """
305+ if isinstance (self .norm , mcolors .BivariateNorm ):
306+ imwidth = A .shape [1 ]
307+ imheight = A .shape [2 ]
308+ else :
309+ imwidth = A .shape [0 ]
310+ imheight = A .shape [1 ]
301311 if A is None :
302312 raise RuntimeError ('You must first set the image '
303313 'array or the image attribute' )
@@ -321,15 +331,15 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
321331 # Flip the input image using a transform. This avoids the
322332 # problem with flipping the array, which results in a copy
323333 # when it is converted to contiguous in the C wrapper
324- t0 = Affine2D ().translate (0 , - A . shape [ 0 ] ).scale (1 , - 1 )
334+ t0 = Affine2D ().translate (0 , - imwidth ).scale (1 , - 1 )
325335 else :
326336 t0 = IdentityTransform ()
327337
328338 t0 += (
329339 Affine2D ()
330340 .scale (
331- in_bbox .width / A . shape [ 1 ] ,
332- in_bbox .height / A . shape [ 0 ] )
341+ in_bbox .width / imheight ,
342+ in_bbox .height / imwidth )
333343 .translate (in_bbox .x0 , in_bbox .y0 )
334344 + self .get_transform ())
335345
@@ -361,17 +371,17 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
361371 if A .ndim not in (2 , 3 ):
362372 raise ValueError ("Invalid dimensions, got {}" .format (A .shape ))
363373
364- if A .ndim == 2 :
365- if not isinstance (self .norm , mcolors .BivariateNorm ):
366- A = self .norm (A )
374+ if A .ndim == 2 or ( A . ndim == 3 and
375+ isinstance (self .norm , mcolors .BivariateNorm ) ):
376+ A = self .norm (A )
367377 if A .dtype .kind == 'f' :
368378 # If the image is greyscale, convert to RGBA and
369379 # use the extra channels for resizing the over,
370380 # under, and bad pixels. This is needed because
371381 # Agg's resampler is very aggressive about
372382 # clipping to [0, 1] and we use out-of-bounds
373383 # values to carry the over/under/bad information
374- rgba = np .empty ((A . shape [ 0 ], A . shape [ 1 ] , 4 ), dtype = A .dtype )
384+ rgba = np .empty ((imwidth , imheight , 4 ), dtype = A .dtype )
375385 rgba [..., 0 ] = A # normalized data
376386 # this is to work around spurious warnings coming
377387 # out of masked arrays.
@@ -410,9 +420,10 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
410420
411421 if not created_rgba_mask :
412422 # Always convert to RGBA, even if only RGB input
423+ isBivari = (A .ndim == 2 and A .shape [0 ] == 2 )
413424 if A .shape [2 ] == 3 :
414425 A = _rgb_to_rgba (A )
415- elif A .shape [2 ] != 4 :
426+ elif A .shape [2 ] != 4 and not isBivari :
416427 raise ValueError ("Invalid dimensions, got %s" % (A .shape ,))
417428
418429 output = np .zeros ((out_height , out_width , 4 ), dtype = A .dtype )
@@ -595,8 +606,9 @@ def set_data(self, A):
595606 not np .can_cast (self ._A .dtype , float , "same_kind" )):
596607 raise TypeError ("Image data cannot be converted to float" )
597608
598- if not (self ._A .ndim == 2
599- or self ._A .ndim == 3 and self ._A .shape [- 1 ] in [3 , 4 ]):
609+ isRGB = (self ._A .ndim == 3 and self ._A .shape [- 1 ] in [3 , 4 ])
610+ isBivari = (self ._A .ndim == 3 and self ._A .shape [0 ] == 2 )
611+ if not (self ._A .ndim == 2 or isRGB or isBivari ):
600612 raise TypeError ("Invalid dimensions for image data" )
601613
602614 self ._imcache = None
0 commit comments