matplotlib之arrow

arrow函数

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

参数

x, y : 箭头起点坐标

dx, dy : 箭头x上的长度和y轴上的长度

width: 箭头宽度,默认0.001

length_includes_head: bool,箭"头"是否包含在长度之中 默认False

head_width: float,箭"头"的宽度,默认: 3*width

head_length: float 箭"头"的长度,默认1.5 * head_width

shape: [‘full’, ‘left’, ‘right’],箭头形状, 默认 ‘full’

overhang: float (default: 0)

head_starts_at_zero: bool (default: False)开始坐标是否是0

返回值

FancyArrow

参数对比实例

# -*- 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

猜你喜欢

转载自my.oschina.net/u/2474629/blog/1794901