Annotating vector plots with a quiver key

We can also add a key to the vectors by using the quiverkey method, and then add the return value that the quiver provides. When we insert the quiver key with the x and y values, say 1 and 9, a string called gradient and another argument saying what the default length will be inserted. We can also add a key to this. By using the quiver key method, we pass the quiver return value, as well as some coordinates in the figure coordinate system (keep in mind this is not the data coordinates), a length that refers to how long in the vector scale we would want this label to be, and a label string called gradient. Here, we can see a nice little label:

# Key
q = plt.quiver(x, y, np.gradient(phi)[1], np.gradient(phi)[0], color='r')
plt.quiverkey(q, 0.1, 0.9, 0.01, "Gradient")

We will get the following output:

Since the label has the same color as the arrows, we can pass color = 'k', which will show a different colored arrow for the key, which tells us that something that is this long has a vector length of 0.01. This is a nice way of telling the viewer how these lengths correspond to data values:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.8.162