From c624d57611c214d90c4bffa06e4fe7e41a7c937b Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 22 Jul 2018 01:32:36 +0200 Subject: [PATCH] Directly get the size of the renderer buffer from the renderer. ... rather than trying to compute it outselves, which can lead to off-by-one errors due to the use of floats in the initial buffer request. --- lib/matplotlib/backends/backend_qt5agg.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backends/backend_qt5agg.py b/lib/matplotlib/backends/backend_qt5agg.py index 6e0e964a8ef2..b009187a49fa 100644 --- a/lib/matplotlib/backends/backend_qt5agg.py +++ b/lib/matplotlib/backends/backend_qt5agg.py @@ -48,10 +48,9 @@ def paintEvent(self, event): [[left, self.renderer.height - (top + height * self._dpi_ratio)], [left + width * self._dpi_ratio, self.renderer.height - top]]) reg = self.copy_from_bbox(bbox) - buf = reg.to_string_argb() + buf = memoryview(reg) qimage = QtGui.QImage( - buf, width * self._dpi_ratio, height * self._dpi_ratio, - QtGui.QImage.Format_ARGB32) + buf, buf.shape[1], buf.shape[0], QtGui.QImage.Format_RGBA8888) if hasattr(qimage, 'setDevicePixelRatio'): # Not available on Qt4 or some older Qt5. qimage.setDevicePixelRatio(self._dpi_ratio)