Content-Length: 9319 | pFad | http://github.com/matplotlib/matplotlib/pull/31438.patch

69DAFE41 From 5cecde19435d7f7f109d0d350fb7d00ea6d1aa5b Mon Sep 17 00:00:00 2001 From: Diksha Date: Thu, 2 Apr 2026 14:22:53 +0530 Subject: [PATCH 1/7] Fix Annotation arrow not updating after setting patchA Setting patchA on Annotation.arrow_patch has no visible effect because the arrow position is not recomputed. This change ensures that the annotation is marked as stale when patchA changes, triggering proper recomputation during rendering. --- lib/matplotlib/text.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 2e870f050209..005d4e84be14 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2101,8 +2101,14 @@ def update_positions(self, renderer): xy=(bbox.x0 - pad / 2, bbox.y0 - pad / 2), width=bbox.width + pad, height=bbox.height + pad, transform=IdentityTransform(), clip_on=False) + old_patchA = self.arrow_patch.patchA self.arrow_patch.set_patchA(patchA) + # Ensure arrow updates when patchA changes + if old_patchA is not patchA: + self.stale = True + + @artist.allow_rasterization def draw(self, renderer): # docstring inherited From 2f804e7b538f09631cfbc2ce10efd43a8fe8eca6 Mon Sep 17 00:00:00 2001 From: Diksha <228217662+dikshajangra12918-oss@users.noreply.github.com> Date: Sun, 5 Apr 2026 12:17:53 +0530 Subject: [PATCH 2/7] Preserve user-set patchA in Annotation.update_positions Add logic to prevent overriding user-set patchA in update_positions. Fixes issues #28316. --- lib/matplotlib/text.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 005d4e84be14..77363ef9fdf2 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2101,14 +2101,18 @@ def update_positions(self, renderer): xy=(bbox.x0 - pad / 2, bbox.y0 - pad / 2), width=bbox.width + pad, height=bbox.height + pad, transform=IdentityTransform(), clip_on=False) - old_patchA = self.arrow_patch.patchA - self.arrow_patch.set_patchA(patchA) - - # Ensure arrow updates when patchA changes - if old_patchA is not patchA: - self.stale = True - + # Check if user manually set patchA externally + current_patchA = self.arrow_patch.patchA + internal_patchA = getattr(self, '_internal_patchA', None) + if current_patchA is not internal_patchA: + # patchA was manually set by the user, do not override it + pass + else: + # patchA was set internally, update it. + self.arrow_patch.set_patchA(patchA) + self._internal_patchA = patchA + @artist.allow_rasterization def draw(self, renderer): # docstring inherited From aa4f232d786907be9338a96f1211d0a65ea87be6 Mon Sep 17 00:00:00 2001 From: Diksha <228217662+dikshajangra12918-oss@users.noreply.github.com> Date: Sun, 5 Apr 2026 12:32:11 +0530 Subject: [PATCH 3/7] Add test_annotation_patchA_not_overridden function Add test to verify that manually set patchA on annotation arrow is preserved after draw. --- lib/matplotlib/tests/test_text.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index 37fee446df5c..f7069c3ec39f 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -1236,3 +1236,16 @@ def test_text_tightbbox_outside_scale_domain(): invalid_text = ax.text(0, -5, 'invalid') invalid_bbox = invalid_text.get_tightbbox(fig.canvas.get_renderer()) assert not np.isfinite(invalid_bbox.width) +def test_annotation_patchA_not_overridden(): + # Test that manually setting patchA on annotation arrow is not overridden by update_positions. See GitHub issue #28316. + fig, ax = plt.subplots() + ann = ax.annotate( + '', + xy=(0.5, 0.6), + xytext=(0.2, 0.5), + arrowprops=dict(arrowstyle="->") + ) + text = ax.text(0.2, 0.5, 'Text', ha='center', va='center') + ann.arrow_patch.set_patchA(text) + fig.draw_without_rendering() + assert ann.arrow_patch.patchA is text From f5f9eecd3adb7895cdb631cf597309ff4ad93c84 Mon Sep 17 00:00:00 2001 From: Diksha <228217662+dikshajangra12918-oss@users.noreply.github.com> Date: Sun, 5 Apr 2026 12:47:42 +0530 Subject: [PATCH 4/7] Fix linting errors in test_text.py 1. Add 2 blank lines before function definition 2. Split long comment line to stay within 80 chars --- lib/matplotlib/tests/test_text.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index f7069c3ec39f..bdea3465c9fb 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -1236,8 +1236,11 @@ def test_text_tightbbox_outside_scale_domain(): invalid_text = ax.text(0, -5, 'invalid') invalid_bbox = invalid_text.get_tightbbox(fig.canvas.get_renderer()) assert not np.isfinite(invalid_bbox.width) + + def test_annotation_patchA_not_overridden(): - # Test that manually setting patchA on annotation arrow is not overridden by update_positions. See GitHub issue #28316. + # Test that manually setting patchA on annotation arrow is not + # overridden by update_positions. See GitHub issue #28316. fig, ax = plt.subplots() ann = ax.annotate( '', From 7e78aadc2b7fe6fcc273b1c925bf66957947176f Mon Sep 17 00:00:00 2001 From: Diksha <228217662+dikshajangra12918-oss@users.noreply.github.com> Date: Sun, 5 Apr 2026 16:58:43 +0530 Subject: [PATCH 5/7] Preserve user-set patchA in update_positions Only update patchA internally if user has not manually set it. --- lib/matplotlib/text.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 77363ef9fdf2..455221837939 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2101,17 +2101,10 @@ def update_positions(self, renderer): xy=(bbox.x0 - pad / 2, bbox.y0 - pad / 2), width=bbox.width + pad, height=bbox.height + pad, transform=IdentityTransform(), clip_on=False) - # Check if user manually set patchA externally - current_patchA = self.arrow_patch.patchA - internal_patchA = getattr(self, '_internal_patchA', None) - - if current_patchA is not internal_patchA: - # patchA was manually set by the user, do not override it - pass - else: - # patchA was set internally, update it. - self.arrow_patch.set_patchA(patchA) - self._internal_patchA = patchA + if self.arrow_patch.patchA is getattr( + self, '_internal_patchA', None): + self.arrow_patch.set_patchA(patchA) + self._internal_patchA = patchA @artist.allow_rasterization def draw(self, renderer): From 0bc1e1ce4920aaef46cb922238c04ca6e09c7307 Mon Sep 17 00:00:00 2001 From: apple Date: Tue, 7 Apr 2026 02:03:54 +0530 Subject: [PATCH 6/7] Fix indentation and Whitespace in update_positions --- lib/matplotlib/text.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 455221837939..0b3b11c08e46 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2101,11 +2101,11 @@ def update_positions(self, renderer): xy=(bbox.x0 - pad / 2, bbox.y0 - pad / 2), width=bbox.width + pad, height=bbox.height + pad, transform=IdentityTransform(), clip_on=False) - if self.arrow_patch.patchA is getattr( + if self.arrow_patch.patchA is getattr( self, '_internal_patchA', None): - self.arrow_patch.set_patchA(patchA) - self._internal_patchA = patchA - + self.arrow_patch.set_patchA(patchA) + self._internal_patchA = patchA + @artist.allow_rasterization def draw(self, renderer): # docstring inherited From fe152c7332413d24adab5a23782ca4d94ae40dfd Mon Sep 17 00:00:00 2001 From: apple Date: Tue, 7 Apr 2026 02:39:07 +0530 Subject: [PATCH 7/7] Fix trailig whitespace --- lib/matplotlib/tests/test_text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index bdea3465c9fb..1677dcce2b2e 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -1239,7 +1239,7 @@ def test_text_tightbbox_outside_scale_domain(): def test_annotation_patchA_not_overridden(): - # Test that manually setting patchA on annotation arrow is not + # Test that manually setting patchA on annotation arrow is not # overridden by update_positions. See GitHub issue #28316. fig, ax = plt.subplots() ann = ax.annotate(








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/matplotlib/matplotlib/pull/31438.patch

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy