From cfff1bc2479be8c795ecbae50bb99247447d0658 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 3 Apr 2020 14:17:01 -0700 Subject: [PATCH] Merge pull request #17017 from jklymak/fix-blended-transform FIX: force blended transforms with data to be in data space --- lib/matplotlib/collections.py | 2 +- lib/matplotlib/tests/test_collections.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 708cdeb22abb..ba1f7c0ffbae 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -221,7 +221,7 @@ def get_datalim(self, transData): # get_path_collection_extents handles nan but not masked arrays if len(paths) and len(offsets): - if transform.contains_branch(transData): + if any(transform.contains_branch_seperately(transData)): # collections that are just in data units (like quiver) # can properly have the axes limits set by their shape + # offset. LineCollections that have no offsets can diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index 0983283ec078..fdd581166a02 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -718,3 +718,17 @@ def test_EventCollection_nosort(): arr = np.array([3, 2, 1, 10]) coll = EventCollection(arr) np.testing.assert_array_equal(arr, np.array([3, 2, 1, 10])) + + +def test_blended_collection_autolim(): + a = [1, 2, 4] + height = .2 + + xy_pairs = np.column_stack([np.repeat(a, 2), np.tile([0, height], len(a))]) + line_segs = xy_pairs.reshape([len(a), 2, 2]) + + f, ax = plt.subplots() + trans = mtransforms.blended_transform_factory(ax.transData, ax.transAxes) + ax.add_collection(LineCollection(line_segs, transform=trans)) + ax.autoscale_view(scalex=True, scaley=False) + np.testing.assert_allclose(ax.get_xlim(), [1., 4.])