簡體   English   中英

如何使用 FancyArrowPatch 制作不同類型的箭頭?

[英]How to make different type of arrowheads using FancyArrowPatch?

我想在 matplotlib 中使用FancyArrowPatch制作以下箭頭:

在此處輸入圖片說明

生成上述圖的代碼是(取自此處):

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(4,4))

v = [-0.2, 0, .2, .4, .6, .8, 1]
for i, overhang in enumerate(v):
    ax.arrow(.1,overhang,.6,0, width=0.001, color="k", 
             head_width=0.1, head_length=0.15, overhang=overhang)

ax.set_yticks(v)
ax.set_xticks([])
ax.set_ylabel("overhang")
ax.set_ylim(-0.3,1.1)
plt.tight_layout()
plt.show()

上面的代碼使用ax.arrow 我如何在FancyArrowPatch實現它?

也許它有助於試驗FancyArrowPatchArrowStyle

from matplotlib.patches import FancyArrowPatch, ArrowStyle
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
style = ArrowStyle('Fancy', head_length=1, head_width=1.5, tail_width=0.5)
arrow = FancyArrowPatch((0, 0), (1, 1), mutation_scale=25, arrowstyle=style, color='k')                     
ax.add_patch(arrow)

plt.xlim(-0.1, 1.1)
plt.ylim(-0.1, 1.1)

現在可以根據需要調整各種參數以獲得所需的結果(例如head_widthhead_lengthmutation_scale ,...)

這個片段使用matplotlib.patches.FancyArrow重現給定的情節:

from matplotlib.patches import FancyArrow
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
v = [-0.2, 0, .2, .4, .6, .8, 1]
for i, overhang in enumerate(v):
    arrow = FancyArrow(0, overhang, 1, 0, width = 0.001, head_width=0.1, head_length = None, color = 'k', overhang = overhang)
    ax.add_patch(arrow)

ax.set_xticks([])
ax.set_yticks(v)
ax.set_ylim(-0.3,1.1)
ax.set_xlim(-0.5, 2)
ax.set_ylabel("overhang")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM