8000 Merge pull request #1497 from akhmerov/master · matplotlib/matplotlib@99d1a2f · GitHub
[go: up one dir, main page]

Skip to content

Commit 99d1a2f

Browse files
committed
Merge pull request #1497 from akhmerov/master
Fix for empty collection check in axes.add_collection
2 parents 20cd99c + d8f3d39 commit 99d1a2f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/matplotlib/axes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,9 +1481,8 @@ def add_collection(self, collection, autolim=True):
14811481

14821482
if collection.get_clip_path() is None:
14831483
collection.set_clip_path(self.patch)
1484-
if autolim:
1485-
if collection._paths and len(collection._paths):
1486-
self.update_datalim(collection.get_datalim(self.transData))
1484+
if autolim and collection._paths and len(collection._offsets):
1485+
self.update_datalim(collection.get_datalim(self.transData))
14871486

14881487
collection._remove_method = lambda h: self.collections.remove(h)
14891488
return collection

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ def test_formatter_ticker():
5454
ax.set_xlabel( "x-label 005" )
5555
ax.autoscale_view()
5656

57+
@cleanup
58+
def test_add_collection():
59+
# Test if data limits are unchanged by adding an empty collection.
60+
# Github issue #1490, pull #1497.
61+
fig = matplotlib.figure.Figure()
62+
fig2 = matplotlib.figure.Figure()
63+
ax = fig.add_subplot(111)
64+
ax2 = fig2.add_subplot(111)
65+
coll = ax2.scatter([0, 1], [0, 1])
66+
ax.add_collection(coll)
67+
bounds = ax.dataLim.bounds
68+
coll = ax2.scatter([], [])
69+
ax.add_collection(coll)
70+
assert ax.dataLim.bounds == bounds
71+
5772
@image_comparison(baseline_images=["formatter_large_small"])
5873
def test_formatter_large_small():
5974
# github issue #617, pull #619

0 commit comments

Comments
 (0)
0