Customizing the appearance of vector plots

This corresponds to what the scale translates into. For instance, a scale unit set to width says that the unit value of 1 is one times the width of your plot. If a scale unit of x says that 1 is one in the width in the x dimension, a scale value of y says the same thing in the y dimension, while the inches says a scale of 1 equals 1 inch long. So, depending on whether or not we want the arrows to scale relative to the size of the image or actual printed image, we would get a value that is independent of the scale of the data itself, which we can specify using the scale units argument.

To customize the appearance of the vector plots, we will take the following steps:

  1. The width of the vectors can also be specified, so, in order to have a one percent size, we need to pass a width of 0.01, as shown:
# Vector width
plt.quiver(x, y, np.gradient(phi)[1], np.gradient(phi)[0], width=0.01)

By executing the preceding code snippet we will get the following output:

  1. We can go even smaller by changing the width to 0.001 so that we get nice, thin little arrows:
# Vector width
plt.quiver(x, y, np.gradient(phi)[1], np.gradient(phi)[0], width=0.001)

  1. We can also pass colors by passing color='r', as follows:
# Vector width
plt.quiver(x, y, np.gradient(phi)[1], np.gradient(phi)[0], color='r')

  1. Like scatter, we can get individual colors for each of the arrows. By passing the keyword argument phi, we can color the vectors as a function, which is a rich way of showing data. Here, we have five-dimensional data, the vector links, and then a color showing the viewer five different kinds of data, not to mention the individual data that varies from point to point. This means that we have a single point conveying five important pieces of information:
# Vector Color
plt.quiver(x, y, np.gradient(phi)[1], np.gradient(phi)[0], phi)

  1. We can also change the pivot. The pivot specifies where on the vector X and Y correspond to, so by default we can use pivot= 'tail', and state that the x and y values correspond to the very end. We can use pivot= 'mid' and pivot= 'tip' as well. The tip, as you might imagine, corresponds to the head part of the vector. As you can see, we have a tail which is the farthest along; we also have the mid in black and the tip in blue. What we are doing is placing these at different positions. Usually, there won't be a reason for you to change this, but if you find that you do need to specify where these x and y coordinates fall on the individual vector arrows, this is the way you can do so:
# Pivot (where the vector goes)
plt.quiver(x, y, np.gradient(phi)[1], np.gradient(phi)[0], color='r', pivot='tail')
plt.quiver(x, y, np.gradient(phi)[1], np.gradient(phi)[0], color='k', pivot='mid')
plt.quiver(x, y, np.gradient(phi)[1], np.gradient(phi)[0], color='b', pivot='tip')

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

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