Skip to content

Commit f62384a

Browse files
committed
NonUniformImage : conversion to RGB array is now done inside *make_image* method. Fixes # 708.
1 parent 1cd07a6 commit f62384a

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

lib/matplotlib/image.py

+22-18
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,34 @@ def _check_unsampled_image(self, renderer):
688688
def make_image(self, magnification=1.0):
689689
if self._A is None:
690690
raise RuntimeError('You must first set the image array')
691+
692+
A = self._A
693+
if len(A.shape) == 2:
694+
if A.dtype != np.uint8:
695+
A = self.to_rgba(A, bytes=True)
696+
self.is_grayscale = self.cmap.is_gray()
697+
else:
698+
A = np.repeat(A[:,:,np.newaxis], 4, 2)
699+
A[:,:,3] = 255
700+
self.is_grayscale = True
701+
else:
702+
if A.dtype != np.uint8:
703+
A = (255*A).astype(np.uint8)
704+
if A.shape[2] == 3:
705+
B = zeros(tuple(list(A.shape[0:2]) + [4]), np.uint8)
706+
B[:,:,0:3] = A
707+
B[:,:,3] = 255
708+
A = B
709+
self.is_grayscale = False
710+
711+
691712
x0, y0, v_width, v_height = self.axes.viewLim.bounds
692713
l, b, r, t = self.axes.bbox.extents
693714
width = (round(r) + 0.5) - (round(l) - 0.5)
694715
height = (round(t) + 0.5) - (round(b) - 0.5)
695716
width *= magnification
696717
height *= magnification
697-
im = _image.pcolor(self._Ax, self._Ay, self._A,
718+
im = _image.pcolor(self._Ax, self._Ay, A,
698719
height, width,
699720
(x0, x0+v_width, y0, y0+v_height),
700721
self._interpd[self._interpolation])
@@ -728,23 +749,6 @@ def set_data(self, x, y, A):
728749
raise TypeError("3D arrays must have three (RGB) or four (RGBA) color components")
729750
if len(A.shape) == 3 and A.shape[2] == 1:
730751
A.shape = A.shape[0:2]
731-
if len(A.shape) == 2:
732-
if A.dtype != np.uint8:
733-
A = self.to_rgba(A, bytes=True)
734-
self.is_grayscale = self.cmap.is_gray()
735-
else:
736-
A = np.repeat(A[:,:,np.newaxis], 4, 2)
737-
A[:,:,3] = 255
738-
self.is_grayscale = True
739-
else:
740-
if A.dtype != np.uint8:
741-
A = (255*A).astype(np.uint8)
742-
if A.shape[2] == 3:
743-
B = zeros(tuple(list(A.shape[0:2]) + [4]), np.uint8)
744-
B[:,:,0:3] = A
745-
B[:,:,3] = 255
746-
A = B
747-
self.is_grayscale = False
748752
self._A = A
749753
self._Ax = x
750754
self._Ay = y

0 commit comments

Comments
 (0)