Open
Description
Bug summary
Creating an empty FancyArrow throws an exception:
>>> import matplotlib.pyplot as plt
>>> plt.arrow([], [], [], [])
matplotlib/axes/_axes.py", line 5509, in arrow
a = mpatches.FancyArrow(x, y, dx, dy, **kwargs)
matplotlib/patches.py", line 1459, in __init__
self._make_verts()
matplotlib/patches.py", line 1518, in _make_verts
if not length:
^^^^^^
ValueError: The truth value of an empty array is ambiguous. Use `array.size > 0` to check that an array is not empty.
That exception used to throw a numpy deprecation warning, but that deprecation has recently expired and now throws an exception.
That section appears to intend to properly handle zero-length input (matplotlib/patches.py", line 1518),
if not length:
self.verts = np.empty([0, 2]) # display nothing if empty
The fix appears to be to change the if not length
to if length.size == 0
.
Code for reproduction
import matplotlib.pyplot as plt
plt.arrow([], [], [], [])
Actual outcome
matplotlib/axes/_axes.py", line 5509, in arrow
a = mpatches.FancyArrow(x, y, dx, dy, **kwargs)
matplotlib/patches.py", line 1459, in __init__
self._make_verts()
matplotlib/patches.py", line 1518, in _make_verts
if not length:
^^^^^^
ValueError: The truth value of an empty array is ambiguous. Use `array.size > 0` to check that an array is not empty.
Expected outcome
Return a valid FancyArrow
Additional information
python version 3.12
matplotlib version: 3.10.3 (latest release)
numpy version: 2.2.6 (deprecation above expired in 2.2.0, released Dec 2024)
Operating system
No response
Matplotlib Version
3.10.3
Matplotlib Backend
No response
Python version
3.12.8
Jupyter version
No response
Installation
pip
Metadata
Metadata
Assignees
Labels
No labels