matplotlib之arrow

arrow函數

matplotlib.pyplot.arrow(
    x, y, dx, dy, 
    hold=None, **kwargs)

參數

x, y : 箭頭起點座標html

dx, dy : 箭頭x上的長度和y軸上的長度api

width: 箭頭寬度,默認0.001函數

length_includes_head: bool,箭"頭"是否包含在長度之中 默認Falsecode

head_width: float,箭"頭"的寬度,默認: 3*widthhtm

head_length: float 箭"頭"的長度,默認1.5 * head_widthutf-8

shape: [‘full’, ‘left’, ‘right’],箭頭形狀, 默認 ‘full’get

overhang: float (default: 0)animation

head_starts_at_zero: bool (default: False)開始座標是不是0it

返回值

FancyArrowio

參數對比實例

# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

ax = plt.subplot(331)
ax.arrow(0, 0, 0.5, 0.5, width=0.05)
ax.set_title("0, 0, 0.5, 0.5, width=0.05")

ax = plt.subplot(332)
ax.arrow(0, 0, 0.5, 0.5, width=0.05,length_includes_head=True)
ax.set_title("0, 0, 0.5, 0.5, width=0.05,length_includes_head=True")

ax = plt.subplot(333)
ax.arrow(0, 0, 0.5, 0.5, width=0.1)
ax.set_title("0, 0, 0.5, 0.5, width=0.1")

ax = plt.subplot(334)
ax.arrow(0, 0, 0.5, 0.5, width=0.05,shape="left")
ax.set_title("0, 0, 0.5, 0.5, width=0.05,shape=left")

ax = plt.subplot(335)
ax.arrow(0, 0, 0.5, 0.5, width=0.05,shape="right")
ax.set_title("0, 0, 0.5, 0.5, width=0.05,shape=right")

ax = plt.subplot(336)
ax.arrow(0, 0, 0.5, 0.5, width=0.05,overhang=0.5)
ax.set_title("0, 0, 0.5, 0.5, width=0.05,overhang=0.5")

ax = plt.subplot(337)
ax.arrow(0, 0, 0.5, 0.5, width=0.05,head_starts_at_zero=True)
ax.set_title("0, 0, 0.5, 0.5, width=0.05,head_starts_at_zero=True")

ax = plt.subplot(338)
ax.arrow(0, 0, 0.5, 0.5, width=0.05,fill=False,ec='red')
ax.set_title("0, 0, 0.5, 0.5, width=0.05,fill=False,ec='red'")

ax = plt.subplot(339)
ax.arrow(0, 0, 0.5, 0.5, width=0.05,fc='red',ec='blue',alpha=0.3)
ax.set_title("0, 0, 0.5, 0.5, width=0.05,fc='red',ec='blue',alpha=0.3")

plt.gcf().set_size_inches(14,12)
plt.savefig('arrow.png')
plt.show()

大概的畫風就像是下面這樣子的:

arrow

參考

matplotlib.patches.FancyArrow

matplotlib.pyplot.arrow

相關文章
相關標籤/搜索