From 606e8e2f7b004efc5d0a726590035ef51ecb3e08 Mon Sep 17 00:00:00 2001 From: nathan78906 Date: Mon, 11 Mar 2019 11:09:25 -0400 Subject: [PATCH] Fix empty FancyArrow crash If dx, dy, and head_length are 0, then creating a FancyArrow will crash(ValueError). This is due to setting verts = []. This gets passed into Path which expects verts to be a Nx2 numpy array. The fix is to set verts to be an empty 0x2 numpy array. --- lib/matplotlib/patches.py | 2 +- lib/matplotlib/tests/test_axes.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index ac86eebc9bc3..708afffd7f35 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -1269,7 +1269,7 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False, else: length = distance + head_length if not length: - verts = [] # display nothing if empty + verts = np.empty([0, 2]) # display nothing if empty else: # start by drawing horizontal arrow, point at (0,0) hw, hl, hs, lw = head_width, head_length, overhang, width diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 45384d6b30fa..58e6e2126b06 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -379,6 +379,12 @@ def test_arrow_simple(): head_length=theta / 10) +def test_arrow_empty(): + _, ax = plt.subplots() + # Create an empty FancyArrow + ax.arrow(0, 0, 0, 0, head_length=0) + + def test_annotate_default_arrow(): # Check that we can make an annotation arrow with only default properties. fig, ax = plt.subplots()