【问题标题】:Matplotlib: how to add an arrow to a Path Patch?Matplotlib:如何向路径补丁添加箭头?
【发布时间】:2018-04-30 03:16:01
【问题描述】:

我有一些路径补丁。

pp1 = mpatches.PathPatch(Path([(start_x, height), (middle_x, middle_y), (end_x, height)],[Path.MOVETO, Path.CURVE3, Path.CURVE3]),fc="none", transform=ax1.transData)
ax1.add_patch(pp1)

这给了我弯曲的边缘,如下图所示:

如何在这些弯曲边缘的末端/开始/中间添加箭头?

我做了一些搜索,发现了其他包含箭头的补丁。我尝试了它们,但将它们与我的路径补丁对齐结果并非易事。我想知道是否有更简单的方法可以在我的边缘添加箭头。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    我认为在任意曲线的中间添加箭头可能是微不足道的,如this answer 所示。

    但是,您可以使用 patches.FancyArrowPatch 在曲线的两端/两端都有箭头:

    import matplotlib.path as mpath
    import matplotlib.patches as mpatches
    import matplotlib.pyplot as plt
    
    Path = mpath.Path
    
    fig, ax = plt.subplots()
    fap1 = mpatches.FancyArrowPatch(path=Path([(0, 0), (1, 1), (1, 0)],
                                             [Path.MOVETO, Path.CURVE3, Path.CURVE3]),
                                    arrowstyle="<|-|>,head_length=10,head_width=10")
    ax.add_patch(fap1)
    ax.set_xlim(-1, 2)
    ax.set_ylim(-1, 2)
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-07
      • 2011-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      相关资源
      最近更新 更多