@@ -396,6 +396,28 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
396396 # scaled data
397397 A_scaled = np .empty (A .shape , dtype = scaled_dtype )
398398 A_scaled [:] = A
399+ # clip scaled data around norm if necessary.
400+ # This is necessary for big numbers at the edge of
401+ # float64's ability to represent changes. Applying
402+ # a norm first would be good, but ruins the interpolation
403+ # of over numbers.
404+ if self .norm .vmin is not None and self .norm .vmax is not None :
405+ dv = (np .float64 (self .norm .vmax ) -
406+ np .float64 (self .norm .vmin ))
407+ vmid = self .norm .vmin + dv / 2
408+ newmin = vmid - dv * 1.e7
409+ if newmin < a_min :
410+ newmin = None
411+ else :
412+ a_min = np .float64 (newmin )
413+ newmax = vmid + dv * 1.e7
414+ if newmax > a_max :
415+ newmax = None
416+ else :
417+ a_max = np .float64 (newmax )
418+ if newmax is not None or newmin is not None :
419+ A_scaled = np .clip (A_scaled , newmin , newmax )
420+
399421 A_scaled -= a_min
400422 # a_min and a_max might be ndarray subclasses so use
401423 # asscalar to ensure they are scalars to avoid errors
@@ -614,7 +636,11 @@ def set_data(self, A):
614636 """
615637 # check if data is PIL Image without importing Image
616638 if hasattr (A , 'getpixel' ):
617- self ._A = pil_to_array (A )
639+ if A .mode == 'L' :
640+ # greyscale image, but our logic assumes rgba:
641+ self ._A = pil_to_array (A .convert ('RGBA' ))
642+ else :
643+ self ._A = pil_to_array (A )
618644 else :
619645 self ._A = cbook .safe_masked_invalid (A , copy = True )
620646
0 commit comments