I have programmed plt.quiver(x,y,u,v,color), where there are arrows that start at x,y and the direction is determined by u,v. My question is how can I know exactly where the arrow ends?
I have programmed plt.quiver(x,y,u,v,color), where there are arrows that start at x,y and the direction is determined by u,v. My question is how can I know exactly where the arrow ends?
In general, the arrows are of length length
as described in the Quiver documentation and are auto-calculated by the matplotlib. I don't know which kwarg may help to return the length.
Another approach could be to define the exact position by scaling the plot with the help of scale=1, units='xy'
.
import numpy as np
import matplotlib.pyplot as plt# define arrow
x = np.linspace(0,1,11)
y = np.linspace(1,0,11)
u = v = np.zeros((11,11))
u[5,5] = 0.3
v[5,5] = 0.3plt.quiver(x, y, u, v, scale=1, units='xy')plt.axis('equal')
plt.xlim(0,1)
plt.ylim(0,1)
plt.show()
Applying the principles above could result in:
import numpy as np
import matplotlib.pyplot as plt
import randomn = 11
cx = 0.7 #x-position of specific end point
cy = 0.5 #y-position of specific end point# define random arrows
x = np.linspace(0,1,n)
y = np.linspace(0,1,n)
u = np.zeros((n,n))
v = np.zeros((n,n))# color everything black
colors = [(0, 0, 0)]*n*n# make sure at least some points end at the same point
u[5][5] = 0.2
u[5][8] = -0.1
v[2][7] = 0.3# search for specific point
for i in range(len(x)):for j in range(len(y)):endPosX = x[i] + u[j][i]endPosY = y[j] + v[j][i]if np.isclose(endPosX, cx) and np.isclose(endPosY, cy):#found specific point -> color it redcolors[j*n+i] = (1,0,0) # plot data
plt.quiver(x, y, u, v, color=colors, scale=1, units='xy')
plt.axis('equal')
plt.show()