From 3f0afd585e3fdf4b3d1554ad017480b832e7a521 Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Tue, 13 Nov 2012 22:41:34 -0500 Subject: [PATCH 1/4] Improve empty collection check in add_collection. --- lib/matplotlib/axes.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index baa86f22cb87..6571a4263d81 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -1491,9 +1491,8 @@ def add_collection(self, collection, autolim=True): if collection.get_clip_path() is None: collection.set_clip_path(self.patch) - if autolim: - if collection._paths and len(collection._paths): - self.update_datalim(collection.get_datalim(self.transData)) + if autolim and collection._paths and len(collection._offsets): + self.update_datalim(collection.get_datalim(self.transData)) collection._remove_method = lambda h: self.collections.remove(h) return collection From 25b7ebd583e6f1a0a6f5fbaf23b930254b2f040a Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Wed, 14 Nov 2012 09:19:06 -0500 Subject: [PATCH 2/4] Add test for add_collection --- lib/matplotlib/tests/test_axes.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 1b7b15b31898..8e2626316f49 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -54,6 +54,18 @@ def test_formatter_ticker(): ax.set_xlabel( "x-label 005" ) ax.autoscale_view() +def test_add_collection(): + fig = matplotlib.figure.Figure() + fig2 = matplotlib.figure.Figure() + ax = fig.add_subplot(111) + ax2 = fig2.add_subplot(111) + coll = ax2.scatter([0, 1], [0, 1]) + ax.add_collection(coll) + bounds = ax.dataLim.bounds + coll = ax2.scatter([], []) + ax.add_collection(coll) + assert ax.dataLim.bounds == bounds + @image_comparison(baseline_images=["formatter_large_small"]) def test_formatter_large_small(): # github issue #617, pull #619 From cd777f30a07285c8c4c6f36ca51e8cea6a1fa78a Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Mon, 4 Feb 2013 08:59:33 -0700 Subject: [PATCH 3/4] add @cleanup to test_add_collection --- lib/matplotlib/tests/test_axes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 8e2626316f49..abd0f015a08e 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -54,6 +54,7 @@ def test_formatter_ticker(): ax.set_xlabel( "x-label 005" ) ax.autoscale_view() +@cleanup def test_add_collection(): fig = matplotlib.figure.Figure() fig2 = matplotlib.figure.Figure() From d8f3d39529c63524faca54cf1585359b190c4e31 Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Thu, 14 Feb 2013 06:47:00 -0500 Subject: [PATCH 4/4] Update lib/matplotlib/tests/test_axes.py --- lib/matplotlib/tests/test_axes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index abd0f015a08e..34639dfc28d3 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -56,6 +56,8 @@ def test_formatter_ticker(): @cleanup def test_add_collection(): + # Test if data limits are unchanged by adding an empty collection. + # Github issue #1490, pull #1497. fig = matplotlib.figure.Figure() fig2 = matplotlib.figure.Figure() ax = fig.add_subplot(111)