From a53833e5115d3d67fc4c3c9307e5f1727c77d128 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 21 Apr 2020 18:13:48 -0700 Subject: [PATCH 1/3] FIX: bypass inverse in collection --- lib/matplotlib/collections.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 181e46b4584f..8d96e677c314 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -234,9 +234,11 @@ def get_datalim(self, transData): # (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) + if not (transOffset.is_affine and (transOffset == transData)): + # Finish the transform started above, but only + # if we have to (to save floating point precision) + offsets = (transOffset.get_affine() + + transData.inverted()).transform(offsets) offsets = np.ma.masked_invalid(offsets) if not offsets.mask.all(): points = np.row_stack((offsets.min(axis=0), From 1422b1b10b28e9bbe784464690b8adbe4250f245 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 22 Apr 2020 10:42:46 -0700 Subject: [PATCH 2/3] FIX: simplify the transform logi --- lib/matplotlib/collections.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 8d96e677c314..88ef027b64bb 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -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) @@ -226,7 +224,8 @@ 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) @@ -234,11 +233,9 @@ def get_datalim(self, transData): # (i.e. like scatter). We can't uniquely set limits based on # those shapes, so we just set the limits based on their # location. - if not (transOffset.is_affine and (transOffset == transData)): - # Finish the transform started above, but only - # if we have to (to save floating point precision) - 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), From 12657ad8c8f2cad705c89bff82a57a6a34f8e99a Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 22 Apr 2020 10:47:40 -0700 Subject: [PATCH 3/3] TST: add a test for singleton on scatter --- lib/matplotlib/tests/test_collections.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index 84eaf25fd4e9..2eaf703474e0 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -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])