Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f091a4d

Browse files
authored
Merge pull request #17206 from jklymak/fix-bypass-inverse-collection
2 parents 50ef5d9 + 12657ad commit f091a4d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/matplotlib/collections.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ def get_datalim(self, transData):
211211
# we may have transform.contains_branch(transData) but not
212212
# transforms.get_affine().contains_branch(transData). But later,
213213
# be careful to only apply the affine part that remains.
214-
if not transOffset.is_affine:
215-
offsets = transOffset.transform_non_affine(offsets)
216214

217215
if isinstance(offsets, np.ma.MaskedArray):
218216
offsets = offsets.filled(np.nan)
@@ -226,17 +224,18 @@ def get_datalim(self, transData):
226224
# also use this algorithm (like streamplot).
227225
result = mpath.get_path_collection_extents(
228226
transform.get_affine(), paths, self.get_transforms(),
229-
offsets, transOffset.get_affine().frozen())
227+
transOffset.transform_non_affine(offsets),
228+
transOffset.get_affine().frozen())
230229
return result.transformed(transData.inverted())
231230
if not self._offsetsNone:
232231
# this is for collections that have their paths (shapes)
233232
# in physical, axes-relative, or figure-relative units
234233
# (i.e. like scatter). We can't uniquely set limits based on
235234
# those shapes, so we just set the limits based on their
236235
# location.
237-
# Finish the transform:
238-
offsets = (transOffset.get_affine() +
239-
transData.inverted()).transform(offsets)
236+
237+
offsets = (transOffset - transData).transform(offsets)
238+
# note A-B means A B^{-1}
240239
offsets = np.ma.masked_invalid(offsets)
241240
if not offsets.mask.all():
242241
points = np.row_stack((offsets.min(axis=0),

lib/matplotlib/tests/test_collections.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,3 +630,10 @@ def test_blended_collection_autolim():
630630
ax.add_collection(LineCollection(line_segs, transform=trans))
631631
ax.autoscale_view(scalex=True, scaley=False)
632632
np.testing.assert_allclose(ax.get_xlim(), [1., 4.])
633+
634+
635+
def test_singleton_autolim():
636+
fig, ax = plt.subplots()
637+
ax.scatter(0, 0)
638+
np.testing.assert_allclose(ax.get_ylim(), [-0.06, 0.06])
639+
np.testing.assert_allclose(ax.get_xlim(), [-0.06, 0.06])

0 commit comments

Comments
 (0)