8000 Fix width/height locations, and forgot to add alpha layer to flatten_… · matplotlib/matplotlib@b8175a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit b8175a1

Browse files
committed
Fix width/height locations, and forgot to add alpha layer to flatten_rgba
1 parent 30c2a09 commit b8175a1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,13 +542,14 @@ def flatten_rgba(self, src, bg=None):
542542

543543
alpha = src[:,:,3]
544544
src_rgb = src[:,:,:3]
545-
h, w, _ = src.shape
545+
w, h, _ = src.shape
546546

547-
result = np.empty((h,w,4))
547+
result = np.empty((w, h, 4))
548548
result[:,:,0] = (255 - alpha)*bg[0] + alpha*src_rgb[:,:,0]
549549
result[:,:,1] = (255 - alpha)*bg[1] + alpha*src_rgb[:,:,1]
550550
result[:,:,2] = (255 - alpha)*bg[2] + alpha*src_rgb[:,:,2]
551551
result = (result/255).astype(np.uint8)
552+
result[:,:,3] = 255
552553
return result
553554

554555
def print_png(self, filename_or_obj, *args, **kwargs):
@@ -566,8 +567,8 @@ def print_png(self, filename_or_obj, *args, **kwargs):
566567
if kwargs.get('flatten', False):
567568
w, h = int(renderer.width), int(renderer.height)
568569
img = renderer._renderer.buffer_rgba()
569-
img = np.array(memoryview(img))
570-
img = self.flatten_rgba(img).reshape((h, w, 4))
570+
img = np.array(memoryview(img)).reshape((h,w,4))
571+
img = self.flatten_rgba(img)
571572
_png.write_png(img, filename_or_obj, self.figure.dpi)
572573
else:
573574
_png.write_png(renderer._renderer, filename_or_obj, self.figure.dpi)

0 commit comments

Comments
 (0)
0