Stream plot
Stream plots (also known as streamline plots) are used to visualize vector fields. They are mostly used in the engineering and scientific communities. It uses vectors and their velocities as a function of base vectors to draw these plots.
Getting ready
Import the required libraries:
import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec
How to do it...
Following code block creates a stream plot:
x, y = np.linspace(-3,3,100), np.linspace(-2,4,50) X, Y = np.meshgrid(x, y) U = 1 - X**2 V = 1 + Y**2 plt.streamplot(X, Y, U, V) plt.title('Basic Streamplot') plt.show()
How it works...
np.linspace(-3, 3, 100)
creates 100 data points in the range of -3 to 3 with equal gap in between consecutive point s. x and y are randomly generated vectors of length 100 and 50 with ranges -3 to 3 and -2 to 4, respectively.np.meshgrid(x, y)
creates the mesh grid as explained earlier in the chapter.- U and V are velocity vectors as a function of x and y. Stream plot is a...