From 1acc296a19d8bf01112b911636d74d8bf0f7b33b Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 8 Jan 2016 20:44:07 -0500 Subject: [PATCH 1/3] Merge pull request #5815 from mdboom/fix-minimizing-raster-layer Properly minimize the rasterized layers Conflicts: lib/matplotlib/tests/test_image.py One too-many tests were cherry-picked --- lib/matplotlib/tests/test_image.py | 36 ++++++++++++++++++++++++++++++ src/_backend_agg.cpp | 8 +++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 6f69822b535d..5a22e5ca6486 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -447,12 +447,48 @@ def test_nonuniformimage_setcmap(): im = NonUniformImage(ax) im.set_cmap('Blues') + @cleanup def test_nonuniformimage_setnorm(): ax = plt.gca() im = NonUniformImage(ax) im.set_norm(plt.Normalize()) + +@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) diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index 9e9ae5ce9f3f..e4721565f52f 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -210,10 +210,10 @@ 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.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); return r; } From 2db55f86f3ef1576d40d05465e47d3eacf4470af Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 10 Jan 2016 13:52:42 -0500 Subject: [PATCH 2/3] TST: skip on py2.6 --- lib/matplotlib/tests/test_image.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 5a22e5ca6486..37a4d94daa5e 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -2,6 +2,7 @@ unicode_literals) from matplotlib.externals import six +import sys import numpy as np @@ -463,6 +464,10 @@ def test_minimized_rasterized(): # 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. + if sys.version_info[:2] < (2, 7): + raise nose.SkipTest("xml.etree.ElementTree.Element.iter " + "added in py 2.7") + from xml.etree import ElementTree np.random.seed(0) From 0631a1de9d78f1bca195125b380d8c8c88b8ffe4 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 10 Jan 2016 14:53:11 -0500 Subject: [PATCH 3/3] TST/MNT: clean up imports in test_image --- lib/matplotlib/tests/test_image.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 37a4d94daa5e..08654ab6c810 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -3,26 +3,31 @@ from matplotlib.externals import six import sys +import io +import os import numpy as np -from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup +from matplotlib.testing.decorators import (image_comparison, + knownfailureif, cleanup) from matplotlib.image import BboxImage, imread, NonUniformImage from matplotlib.transforms import Bbox from matplotlib import rcParams import matplotlib.pyplot as plt -from nose.tools import assert_raises -from numpy.testing import assert_array_equal, assert_array_almost_equal -import io -import os +from numpy.testing import assert_array_equal + + +import nose try: from PIL import Image + del Image HAS_PIL = True except ImportError: HAS_PIL = False + @image_comparison(baseline_images=['image_interps']) def test_image_interps(): 'make the basic nearest, bilinear and bicubic interps'