matplotlib - Python matlibplot Arrow pointing to a point on a curve -
i trying plot arrows pointing @ point on curve in python using matplotlib.
on line need point vertical arrows @ specific points. indicating forces acting on beam, direction important. curve beam , arrow force.
i know coordinate of said point, exactly, of cause changing input. input should dictate whether arrow points upwards or downwards line. (negative , positive forces applied). have tried endlessly plt.arrow, because scale changes drastically , quadrant in arrow has be. might have start @ y < 0 , end in point y > 0. problem arrowhead length points wrong way --<. instead of -->.
so before go bald because of this, know if there easy way apply vertical arrow (could infinite in opposite direction care) pointing point on curve, of can control whether point upwards curve, or downwards curve.
i'm not sure follow you, approach use annotate
rather arrow
(just leave text field blank). can specify 1 end of arrow in data coordinates , other in offset pixels: have map forces (indicating length of arrows) number of pixels. example:
import matplotlib.pyplot plt import numpy np # trial function adding vertical arrows def f(x): return np.sin(2*x) x = np.linspace(0,10,1000) y = f(x) fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x,y, 'k', lw=2) ax.set_ylim(-3,3) def add_force(f, x1): """add vertical force arrow f pixels long @ x1 (in data coordinates).""" ax.annotate('', xy=(x1, f(x1)), xytext=(0, f), textcoords='offset points', arrowprops=dict(arrowstyle='<|-', color='r')) add_force(60, 4.5) add_force(-45, 6.5) plt.show()