gpt4 book ai didi

matplotlib - 更改 matplotlib quiver 函数的箭头样式

转载 作者:行者123 更新时间:2023-12-01 03:39:52 28 4
gpt4 key购买 nike

有没有办法改变matplotlib quiver function的箭头样式?

我尝试通过 arrowprops=dict() kwarg 到函数,但这似乎只适用于 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()

类似问题:
  • How to use custom marker with plot?
  • Matplotlib custom marker/symbol
  • 最佳答案

    注:这只是部分答案,关于 arrowprops=dict() 的使用.

    Part of the problem as that there are 7 (!) artists that can be used to draw arrows (Arrow, FancyArrow, FancyArrowPatch, ConnectionPatch, YAArrow, SimpleArrow (which is a sub-class of FancyArrowPatch) and FilledArrow) all of which behave differently and have different interfaces.

    This does not include quiver which does draw arrows, but is a PolyCollection sub-class.


    您可以阅读有关此箭头讨论的更多信息 here .
    还提到一些函数会根据给定的参数自动更改箭头样式:

    [...] the issue with the annotate function is that it's not obvious to a user that the API changes when specifying a different arrowstyle.


    我遇到了类似的问题 annotate ,您可能会看到 in this question .

    关于matplotlib - 更改 matplotlib quiver 函数的箭头样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31663535/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com