From cb9b2efc00e5c503b6984dd82bd94f913c9e9e76 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 17 Apr 2023 20:46:18 -0400 Subject: [PATCH 1/4] fixed issue #25682 --- lib/matplotlib/axes/_axes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index cd03957dbbfa..5963119ca756 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5409,7 +5409,10 @@ def get_interp_point(idx): np.column_stack([ind[where], dep2[where]])]) if ind_dir == "y": pts = pts[:, ::-1] - self.update_datalim(pts, updatex=True, updatey=True) + + if "transform" not in kwargs: + self.update_datalim(pts, updatex=True, updatey=True) + self.add_collection(collection, autolim=False) self._request_autoscale_view() return collection From 863502e13a395c740be8117cfbf17999326a8514 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 21 Apr 2023 14:02:15 -0400 Subject: [PATCH 2/4] Added unit test to verify axes limits in Axes.fill_between --- lib/matplotlib/tests/test_axes.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 863e3e2f86a6..1d0457d17855 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -8558,3 +8558,19 @@ def test_ecdf_invalid(): plt.ecdf([1, np.nan]) with pytest.raises(ValueError): plt.ecdf(np.ma.array([1, 2], mask=[True, False])) + + +def test_fill_between_axes_limits(): + fig, ax = plt.subplots() + x = np.arange(0, 4 * np.pi, 0.01) + y = 0.1*np.sin(x) + threshold = 0.075 + ax.plot(x, y, color='black') + + original_lims = (ax.get_xlim(), ax.get_ylim()) + + ax.axhline(threshold, color='green', lw=2, alpha=0.7) + ax.fill_between(x, 0, 1, where=y > threshold, + color='green', alpha=0.5, transform=ax.get_xaxis_transform()) + + assert (ax.get_xlim(), ax.get_ylim()) == original_lims From c2f84c0f92466166a9a1419b8de88611d9548e9a Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 22 Apr 2023 20:39:10 -0400 Subject: [PATCH 3/4] updated to check transform branches --- lib/matplotlib/axes/_axes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 5963119ca756..44e1c0c1bad7 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5410,8 +5410,10 @@ def get_interp_point(idx): if ind_dir == "y": pts = pts[:, ::-1] - if "transform" not in kwargs: - self.update_datalim(pts, updatex=True, updatey=True) + up_x, up_y = True, True + if "transform" in kwargs: + up_x, up_y = kwargs["transform"].contains_branch_seperately(self.transData) + self.update_datalim(pts, updatex=up_x, updatey=up_y) self.add_collection(collection, autolim=False) self._request_autoscale_view() From 8c5305fffc420c53b608757c04368463febc0e26 Mon Sep 17 00:00:00 2001 From: Olin Johnson <56653927+olinjohnson@users.noreply.github.com> Date: Thu, 27 Apr 2023 21:41:33 -0400 Subject: [PATCH 4/4] Update lib/matplotlib/axes/_axes.py Co-authored-by: Elliott Sales de Andrade --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 44e1c0c1bad7..9eb083321e41 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5410,7 +5410,7 @@ def get_interp_point(idx): if ind_dir == "y": pts = pts[:, ::-1] - up_x, up_y = True, True + up_x = up_y = True if "transform" in kwargs: up_x, up_y = kwargs["transform"].contains_branch_seperately(self.transData) self.update_datalim(pts, updatex=up_x, updatey=up_y)