From 1c17bb4b34afc2f5b63bd6e728b1881c59f34a2f Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 25 Feb 2013 10:26:37 -0500 Subject: [PATCH 1/3] Fix Python 3 bug in PS backend. --- lib/matplotlib/backends/backend_ps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 5a0d9ead019d..265329c564c7 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 From 87cf619440b8a4d37c7e50058e6a6969a0e35427 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 28 Feb 2013 09:04:43 -0500 Subject: [PATCH 2/3] Another Python3 bytes/unicode fix --- lib/matplotlib/backends/backend_ps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 265329c564c7..d85e75993bed 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -1187,7 +1187,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 From df8c010dd8c4739edcb993083bdd758e09c7fd29 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 28 Feb 2013 09:09:01 -0500 Subject: [PATCH 3/3] Flush file handles at the end, since Python 3 won't do it for us. --- lib/matplotlib/backends/backend_ps.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index d85e75993bed..deede3a602f3 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -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) @@ -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