From ec456308fccfd32a05928b71376c59cd4af458cb Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 8 Jan 2016 12:39:29 -0500 Subject: [PATCH 1/3] Fix #5814 The creation of the bounding box of actual image content is wrong. --- src/_backend_agg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index 9e9ae5ce9f3f..d5da1d0bf052 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -212,8 +212,8 @@ agg::rect_i RendererAgg::get_content_extents() r.x1 = std::max(0, r.x1 - 1); r.y1 = std::max(0, r.y1 - 1); - r.x2 = std::max(r.x2 + 1, (int)width); - r.y2 = std::max(r.y2 + 1, (int)height); + r.x2 = std::min(r.x2 + 1, (int)width); + r.y2 = std::min(r.y2 + 1, (int)height); return r; } From 87d82ab348caeb083bf487d69bf393aada4154d1 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 8 Jan 2016 12:52:11 -0500 Subject: [PATCH 2/3] Add test --- lib/matplotlib/tests/test_image.py | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index ae1379a4e796..d8a5bf54614e 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -481,6 +481,40 @@ def test_jpeg_alpha(): assert image.getpixel((0, 0)) == (254, 0, 0) +@cleanup +def test_minimized_rasterized(): + # This ensures that the rasterized content in the colorbars is + # only as thick as the colorbar, and doesn't extend to other parts + # of the image. See #5814. While the original bug exists only + # in Postscript, the best way to detect it is to generate SVG + # and then parse the output to make sure the two colorbar images + # are the same size. + from xml.etree import ElementTree + + np.random.seed(0) + data = np.random.rand(10, 10) + + fig, ax = plt.subplots(1, 2) + p1 = ax[0].pcolormesh(data) + p2 = ax[1].pcolormesh(data) + + plt.colorbar(p1, ax=ax[0]) + plt.colorbar(p2, ax=ax[1]) + + buff = io.BytesIO() + plt.savefig(buff, format='svg') + + buff = io.BytesIO(buff.getvalue()) + tree = ElementTree.parse(buff) + width = None + for image in tree.iter('image'): + if width is None: + width = image['width'] + else: + if image['width'] != width: + assert False + + if __name__=='__main__': import nose nose.runmodule(argv=['-s','--with-doctest'], exit=False) From 2c99e51602a59605fdbb1d8c6eb1ee951d173a8e Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 8 Jan 2016 13:47:53 -0500 Subject: [PATCH 3/3] Remove unnecessary -1's --- src/_backend_agg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index d5da1d0bf052..e4721565f52f 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -210,8 +210,8 @@ agg::rect_i RendererAgg::get_content_extents() } } - r.x1 = std::max(0, r.x1 - 1); - r.y1 = std::max(0, r.y1 - 1); + r.x1 = std::max(0, r.x1); + r.y1 = std::max(0, r.y1); r.x2 = std::min(r.x2 + 1, (int)width); r.y2 = std::min(r.y2 + 1, (int)height);