Making vector plots with quiver

We want to plot both the X and the Y changes together. For this, we can use the quiver method. To use the quiver method, insert the (phi) [1] and (phi) [0] gradients into the gradient method. When we call this default set of arguments, the x and y positions, as well as the length of the x and y vectors we provide, will create the following vector field:

# Vectors with quiver
plt.imshow(phi, extent=(0,10,0,10), interpolation='none', origin='lower')
plt.quiver(x, y, np.gradient(phi)[0], np.gradient(phi)[1])

Following is the output of the preceding code:

We can also change the scale. Usually, after passing a scale of 1, we would get the same length vectors but, here, the scale isn't a single constant value. Instead, what it says is how many units in the vector dimension are required to give a constant unit length vector, as shown in the following code:

# Vector scale
plt.quiver(x, y, np.gradient(phi)[1], np.gradient(phi)[0], scale=1)

Following is the output of the preceding code snippet:

This is why we get bigger vectors with bigger values by changing the scale to 10, as shown in the following output:

To get bigger vectors with smaller values of scale change the value, that is scale=0.1, we can perform the following:

There are a number of different ways for deciding the width, inches, and so on, using the scale_units argument. By default, this argument uses width. Hence, while specifying width, we will get exactly the same output as shown:

# Units (x,y,height,width,inches)
plt.quiver(x, y, np.gradient(phi)[1], np.gradient(phi)[0], scale_units='width', scale=0.1)

After, we pass the inches function, we get the following:

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

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