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 diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 1b7b15b31898..34639dfc28d3 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -54,6 +54,21 @@ def test_formatter_ticker(): ax.set_xlabel( "x-label 005" ) ax.autoscale_view() +@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) + 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