Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ def get_datalim(self, transData):
# we may have transform.contains_branch(transData) but not
# transforms.get_affine().contains_branch(transData). But later,
# be careful to only apply the affine part that remains.
if not transOffset.is_affine:
offsets = transOffset.transform_non_affine(offsets)

if isinstance(offsets, np.ma.MaskedArray):
offsets = offsets.filled(np.nan)
Expand All @@ -226,17 +224,18 @@ def get_datalim(self, transData):
# also use this algorithm (like streamplot).
result = mpath.get_path_collection_extents(
transform.get_affine(), paths, self.get_transforms(),
offsets, transOffset.get_affine().frozen())
transOffset.transform_non_affine(offsets),
transOffset.get_affine().frozen())
return result.transformed(transData.inverted())
if not self._offsetsNone:
# this is for collections that have their paths (shapes)
# in physical, axes-relative, or figure-relative units
# (i.e. like scatter). We can't uniquely set limits based on
# those shapes, so we just set the limits based on their
# location.
# Finish the transform:
offsets = (transOffset.get_affine() +
transData.inverted()).transform(offsets)

offsets = (transOffset - transData).transform(offsets)
# note A-B means A B^{-1}
offsets = np.ma.masked_invalid(offsets)
if not offsets.mask.all():
points = np.row_stack((offsets.min(axis=0),
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,10 @@ def test_blended_collection_autolim():
ax.add_collection(LineCollection(line_segs, transform=trans))
ax.autoscale_view(scalex=True, scaley=False)
np.testing.assert_allclose(ax.get_xlim(), [1., 4.])


def test_singleton_autolim():
fig, ax = plt.subplots()
ax.scatter(0, 0)
np.testing.assert_allclose(ax.get_ylim(), [-0.06, 0.06])
np.testing.assert_allclose(ax.get_xlim(), [-0.06, 0.06])