matplotlibのarrowで'vertices' must be a 2D list ... と怒られる場合の対処法

#問題設定

pythonのmatplotlibには矢印を表示する関数が用意されています．

```python 
import matplotlib.pyplot as plt

dx = 0.3
dy = 0.3
params = {
    'width':0.01,
    }
plt.arrow(0, 0, dx, dy, **params)
plt.xlim(-0.5, 0.5)
plt.ylim(-0.5, 0.5)
plt.show()
```
![Figure.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328786/f9ac96e5-e2c1-e5f8-db4f-754d1df27296.png)

矢印の始点と終点を設定する際，矢印に鏃を含むか含まないかをlength_includes_headで設定できます．
デフォルトだと含まない設定です．

```python
import matplotlib.pyplot as plt

dx = 0.0
dy = 0.2
params = {
    'width':0.01,
    }
plt.arrow(-0.1, 0, dx, dy, **params)

params = {
    'width':0.01,
    'length_includes_head':True,
    }
plt.arrow(0.1, 0, dx, dy, **params)

plt.grid()

plt.xlim(-0.5, 0.5)
plt.ylim(-0.5, 0.5)
plt.show()
```

![Figure_.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328786/3152a2cc-fa91-e061-5220-6d75d8f5912d.png)

長さ0の矢印を描画する場合，鏃を含むか含まないかで結果が変わり，鏃を含むとエラーが出ます.


鏃を含まない場合:

```python:test1.py
import matplotlib.pyplot as plt

dx = 0.0
dy = 0.0
params = {
    'width':0.01,
    }
plt.arrow(0, 0, dx, dy, **params)
plt.xlim(-0.5, 0.5)
plt.ylim(-0.5, 0.5)
plt.show()
```

![Figure_1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328786/9037bc96-b1d2-b33b-a406-b8243d6d5fd0.png)

鏃を含む場合:

```python:test2.py
import matplotlib.pyplot as plt

dx = 0.0
dy = 0.0
params = {
    'width':0.01,
    'length_includes_head':True,
    }
plt.arrow(0, 0, dx, dy, **params)
plt.xlim(-0.5, 0.5)
plt.ylim(-0.5, 0.5)
plt.show()
```

```
Traceback (most recent call last):
  File "test2.py", line 9, in <module>
    plt.arrow(0, 0, dx, dy, **params)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py", line 2411, in arrow
    return gca().arrow(x, y, dx, dy, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/axes/_axes.py", line 4822, in arrow
    a = mpatches.FancyArrow(x, y, dx, dy, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/patches.py", line 1269, in __init__
    super().__init__(verts, closed=True, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/patches.py", line 938, in __init__
    self.set_xy(xy)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/patches.py", line 1005, in set_xy
    self._path = Path(xy, closed=self._closed)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/path.py", line 130, in __init__
    "'vertices' must be a 2D list or array with shape Nx2")
ValueError: 'vertices' must be a 2D list or array with shape Nx2
```

#対処法

##対処法1

矢印の長さと矢印の幅等をいい感じに変えればエラーが消えます．

```python
import matplotlib.pyplot as plt

dx = 1.0e-8
dy = 0.0
params = {
    'width':1.0e-8,
    'length_includes_head':True,
    }
plt.arrow(0, 0, dx, dy, **params)
plt.xlim(-0.5, 0.5)
plt.ylim(-0.5, 0.5)
plt.show()
```

(何も表示されないので表示結果は略)

##対処法2

元凶はmatplotlib/patches.py (私の環境では /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/patches.py ) の1227行目付近の以下の文

```python
        if not length:
            verts = []  # display nothing if empty
        else:
            ...
```

で，verts = [] が型違いで怒られています．
もっとも簡単な修正方法は，その直前でlength等を適当に設定してしまうことです．

```python
        if not length:
          length = distance = 1.0E-8

        if not length:
            verts = []  # display nothing if empty
        else:
            ...
```

(何も表示されないので表示結果は略)

#おまけ

矢印の長さが鏃の大きさより小さいと表示が変になるので注意してください．

```python
import matplotlib.pyplot as plt

dx = 0.001
dy = 0.0
params = {
    'width':0.01,
    'length_includes_head':True,
    }
plt.arrow(0, 0, dx, dy, **params)
plt.xlim(-0.5, 0.5)
plt.ylim(-0.5, 0.5)
plt.show()
```

![Figure_2_1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328786/948acec0-643e-49b1-af6d-0598a6d67a10.png)