Making stream plots

We also have another option for plotting vectors, and that is by using the streamplot as shown in the following points:

  1. The stream plot will actually follow stream lines, so they will generate smooth curves that go along the lines. An example of this is shown in the following code:
# Stream plot
plt.streamplot(x, y, np.gradient(phi)[1], np.gradient(phi)[0])

Following is the output of the preceding code:

In the stream plot, we can specify a density argument that tells us how many of these lines per unit area we get. We can see that a density of 1 gives you more or less what we had before.

  1. When we double the density with 2, we get a variation, as follows:
# Stream plot density
plt.streamplot(x, y, np.gradient(phi)[1], np.gradient(phi)[0], density=2)

  1. When we double the density with 0.5, we get the following:
# Stream plot density
plt.streamplot(x, y, np.gradient(phi)[1], np.gradient(phi)[0], density=0.5)

  1. Next, we will customize the color argument. Just like with the quiver, we will make individual colors for the lines. Unlike the quivers, which had different arrows for each different point, we can actually change the colors along our line, like so:
# Stream plot linewidth
delta = phi-np.mean(phi)
plt.streamplot(x, y, np.gradient(phi)[1], np.gradient(phi)[0], color=phi)

Following is the output of the preceding code:

  1. To change the width of the lines, we can color them based on the value. The size of these lines can also be changed based on changing phi. By doing this, we get infinitesimal lines near the middle of the plot, where the average value is more or less equal to the current value of this scalar field:
# Stream plot linewidth
delta = phi-np.mean(phi)
plt.streamplot(x, y, np.gradient(phi)[1], np.gradient(phi)[0], linewidth=delta)

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

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