diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 5a0d9ead019d..deede3a602f3 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -469,7 +469,7 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None): im.flipud_out() h, w, bits, imagecmd = self._get_image_h_w_bits_command(im) - hexlines = '\n'.join(self._hex_lines(bits)) + hexlines = b'\n'.join(self._hex_lines(bits)).decode('ascii') if dx is None: xscale = w / self.image_magnification @@ -1179,6 +1179,7 @@ def write(self, *kl, **kwargs): print("end", file=fh) print("showpage", file=fh) if not isEPSF: print("%%EOF", file=fh) + fh.flush() if rcParams['ps.usedistiller'] == 'ghostscript': gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox) @@ -1187,7 +1188,7 @@ def write(self, *kl, **kwargs): if passed_in_file_object: with open(tmpfile, 'rb') as fh: - print(fh.read(), file=outfile) + outfile.write(fh.read()) else: with open(outfile, 'w') as fh: pass @@ -1293,6 +1294,7 @@ def write(self, *kl, **kwargs): #print >>fh, "grestore" print("end", file=fh) print("showpage", file=fh) + fh.flush() if isLandscape: # now we are ready to rotate isLandscape = True