Is there a way to change the style of the arrows of the matplotlib quiver function?
I tried passing the arrowprops=dict()
kwarg to the function, but that seems to only work with annotate function.
In any case the arrow style I am looking for, does not seem to be included in matplotlib. I think they are called "half arrows". I can insert these arrows using UTF-8 characters, but the arrows can then not be customized and it is hard to get them aligned properly. Is there a better way to do this (Maybe with inserting a SVG symbol)?
The code of my solution above:
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()
Similar questions:
Note: This is only a partial answer, about the use of 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.
You can read more on this arrows discussion here.
Also mentioned there is that some functions change the arrow style automatically, according to the parameters given:
[...] the issue with the annotate function is that it's not obvious to a user that the API changes when specifying a different arrowstyle.
I had a similar issue with annotate
, which you may see in this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With