From 9e2d964913058a94ad6e9aeb65a368fc79e58535 Mon Sep 17 00:00:00 2001 From: N R Navaneet Date: Wed, 2 Jul 2025 07:13:20 +0530 Subject: [PATCH 1/6] WIP: changed FancyArrow empty logic --- lib/matplotlib/patches.py | 2 +- lib/matplotlib/tests/test_patches.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 63453d416b99..dfbc9d94edbe 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -1538,7 +1538,7 @@ def _make_verts(self): length = distance else: length = distance + head_length - if not length: + if (isinstance(length, np.ndarray) and length.size == 0) or (not length): self.verts = np.empty([0, 2]) # display nothing if empty else: # start by drawing horizontal arrow, point at (0, 0) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 4ed9222eb95e..cf9f3c1b5587 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -1093,3 +1093,9 @@ def test_facecolor_none_edgecolor_force_edgecolor(): rcParams['patch.edgecolor'] = 'red' rect = Rectangle((0, 0), 1, 1, facecolor="none") assert mcolors.same_color(rect.get_edgecolor(), rcParams['patch.edgecolor']) + +def test_empty_fancyarrow(): + import matplotlib.pyplot as plt + fig, ax = plt.subplots() + arrow = ax.arrow([], [], [], []) + assert arrow is not None From 8e8aac80df863bae3148f926869e3fad3d4019ee Mon Sep 17 00:00:00 2001 From: N R Navaneet <156576749+nrnavaneet@users.noreply.github.com> Date: Wed, 2 Jul 2025 07:19:43 +0530 Subject: [PATCH 2/6] Update test_patches.py --- lib/matplotlib/tests/test_patches.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index cf9f3c1b5587..6b4d477ad6a4 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -1094,8 +1094,10 @@ def test_facecolor_none_edgecolor_force_edgecolor(): rect = Rectangle((0, 0), 1, 1, facecolor="none") assert mcolors.same_color(rect.get_edgecolor(), rcParams['patch.edgecolor']) + def test_empty_fancyarrow(): import matplotlib.pyplot as plt fig, ax = plt.subplots() + arrow = ax.arrow([], [], [], []) assert arrow is not None From 2151c191e6af391db263682ae92689f89bf7460d Mon Sep 17 00:00:00 2001 From: N R Navaneet <156576749+nrnavaneet@users.noreply.github.com> Date: Wed, 2 Jul 2025 07:21:27 +0530 Subject: [PATCH 3/6] Update test_patches.py From 070837bff5c5c9ee446bd75989b3994bef157f04 Mon Sep 17 00:00:00 2001 From: N R Navaneet Date: Wed, 2 Jul 2025 07:30:52 +0530 Subject: [PATCH 4/6] Fix crash when drawing FancyArrow with zero length --- .python-version | 1 + lib/matplotlib/tests/test_patches.py | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 .python-version diff --git a/.python-version b/.python-version new file mode 100644 index 000000000000..9919bf8c9031 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.10.13 diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 6b4d477ad6a4..d69a9dad4337 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -1096,8 +1096,6 @@ def test_facecolor_none_edgecolor_force_edgecolor(): def test_empty_fancyarrow(): - import matplotlib.pyplot as plt fig, ax = plt.subplots() - arrow = ax.arrow([], [], [], []) assert arrow is not None From 75a0476a8fc651a4612ba5c8a99fa1e223da553d Mon Sep 17 00:00:00 2001 From: N R Navaneet <156576749+nrnavaneet@users.noreply.github.com> Date: Thu, 3 Jul 2025 04:11:15 +0530 Subject: [PATCH 5/6] Update patches.py --- lib/matplotlib/patches.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index dfbc9d94edbe..477eee9f5a7a 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -1538,7 +1538,7 @@ def _make_verts(self): length = distance else: length = distance + head_length - if (isinstance(length, np.ndarray) and length.size == 0) or (not length): + if np.size(length) == 0: self.verts = np.empty([0, 2]) # display nothing if empty else: # start by drawing horizontal arrow, point at (0, 0) From 2a220e18a0c74b33a943a9764b5cd1f3671816e9 Mon Sep 17 00:00:00 2001 From: N R Navaneet <156576749+nrnavaneet@users.noreply.github.com> Date: Thu, 3 Jul 2025 04:11:56 +0530 Subject: [PATCH 6/6] Delete .python-version --- .python-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .python-version diff --git a/.python-version b/.python-version deleted file mode 100644 index 9919bf8c9031..000000000000 --- a/.python-version +++ /dev/null @@ -1 +0,0 @@ -3.10.13