@@ -681,13 +681,34 @@ def _check_unsampled_image(self, renderer):
681
681
def make_image (self , magnification = 1.0 ):
682
682
if self ._A is None :
683
683
raise RuntimeError ('You must first set the image array' )
684
+
685
+ A = self ._A
686
+ if len (A .shape ) == 2 :
687
+ if A .dtype != np .uint8 :
688
+ A = self .to_rgba (A , bytes = True )
689
+ self .is_grayscale = self .cmap .is_gray ()
690
+ else :
691
+ A = np .repeat (A [:,:,np .newaxis ], 4 , 2 )
692
+ A [:,:,3 ] = 255
693
+ self .is_grayscale = True
694
+ else :
695
+ if A .dtype != np .uint8 :
696
+ A = (255 * A ).astype (np .uint8 )
697
+ if A .shape [2 ] == 3 :
698
+ B = zeros (tuple (list (A .shape [0 :2 ]) + [4 ]), np .uint8 )
699
+ B [:,:,0 :3 ] = A
700
+ B [:,:,3 ] = 255
701
+ A = B
702
+ self .is_grayscale = False
703
+
704
+
684
705
x0 , y0 , v_width , v_height = self .axes .viewLim .bounds
685
706
l , b , r , t = self .axes .bbox .extents
686
707
width = (round (r ) + 0.5 ) - (round (l ) - 0.5 )
687
708
height = (round (t ) + 0.5 ) - (round (b ) - 0.5 )
688
709
width *= magnification
689
710
height *= magnification
690
- im = _image .pcolor (self ._Ax , self ._Ay , self . _A ,
711
+ im = _image .pcolor (self ._Ax , self ._Ay , A ,
691
712
height , width ,
692
713
(x0 , x0 + v_width , y0 , y0 + v_height ),
693
714
self ._interpd [self ._interpolation ])
@@ -721,23 +742,6 @@ def set_data(self, x, y, A):
721
742
raise TypeError ("3D arrays must have three (RGB) or four (RGBA) color components" )
722
743
if len (A .shape ) == 3 and A .shape [2 ] == 1 :
723
744
A .shape = A .shape [0 :2 ]
724
- if len (A .shape ) == 2 :
725
- if A .dtype != np .uint8 :
726
- A = self .to_rgba (A , bytes = True )
727
- self .is_grayscale = self .cmap .is_gray ()
728
- else :
729
- A = np .repeat (A [:,:,np .newaxis ], 4 , 2 )
730
- A [:,:,3 ] = 255
731
- self .is_grayscale = True
732
- else :
733
- if A .dtype != np .uint8 :
734
- A = (255 * A ).astype (np .uint8 )
735
- if A .shape [2 ] == 3 :
736
- B = zeros (tuple (list (A .shape [0 :2 ]) + [4 ]), np .uint8 )
737
- B [:,:,0 :3 ] = A
738
- B [:,:,3 ] = 255
739
- A = B
740
- self .is_grayscale = False
741
745
self ._A = A
742
746
self ._Ax = x
743
747
self ._Ay = y
0 commit comments