修改 matplotlib quiver 函数的箭头风格

5
有没有办法更改 matplotlib quiver function 箭头的样式?
我尝试将 arrowprops=dict() 传递给函数,但似乎只适用于 annotate function
无论如何,我要寻找的箭头样式似乎没有包含在 matplotlib 中。我认为它们被称为 "半箭头"。 我可以使用 UTF-8 字符插入这些箭头,但是箭头无法自定义,并且很难使它们对齐。是否有更好的方法做到这一点(也许是通过插入 SVG 符号)?

enter image description here

上面是我的解决方案的代码:

import matplotlib.pyplot as plt
import numpy as np
import mplstereonet
import matplotlib.image as image

#UTF-8 characters don't seem to work in the normal pyplot backend
plt.switch_backend("gtk3cairo")

fig = plt.figure()
ax = fig.add_subplot(111, projection='stereonet')

arrows = [[120, 30, 120, 30, "sin"],
          [160, 50, 160, 50, "dex"]]

for arrow in arrows:
    strike = arrow[0] - 90
    ax.plane(strike, arrow[1], color="#000000")
    ax.line(arrow[3], arrow[2], color="#ff0000")

    x, y = mplstereonet.line(arrow[3], arrow[2])
    ang = np.degrees(np.arctan2(x, y))[0] * (-1)
    gap = 0.08
    gap_x = gap * np.sin(ang)
    gap_y = gap * np.cos(ang)

    if arrow[4] == "dex":
        ax.text(x - gap_x, y - gap_y, "⇀", size=30, rotation=ang,
                horizontalalignment="center", verticalalignment="center")
        ax.text(x + gap_x, y + gap_y, "↽", size=30, rotation=ang,
                horizontalalignment="center", verticalalignment="center")

    elif arrow[4] == "sin":
        ax.text(x - gap_x, y - gap_y, "↼", size=30, rotation=ang,
                horizontalalignment="center", verticalalignment="center")
        ax.text(x + gap_x, y + gap_y, "⇁", size=30, rotation=ang,
                horizontalalignment="center", verticalalignment="center")

plt.show()

类似的问题:

1个回答

2

注意: 这只是有关使用arrowprops=dict()的部分答案。


问题的一部分在于Matplotlib提供了7种不同的绘制箭头的方法(Arrow、FancyArrow、FancyArrowPatch、ConnectionPatch、YAArrow、SimpleArrow(它是FancyArrowPatch的子类)和FilledArrow),它们的行为和接口都不相同。

这还不包括quiver,它可以绘制箭头,但是它是PolyCollection的子类。

您可以在此处阅读更多关于箭头讨论的内容here

该讨论还提到一些函数根据给定的参数自动更改箭头样式:

[...] annotate函数的问题在于,当指定不同的箭头样式时,用户并不明显地意识到API会发生变化。

我在annotate中遇到了类似的问题,您可以在这个问题here看到。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接