PLOTTING RANDOMIZED POINTS WITH NUMPY AND MATPLOTLIB
The previous section contains simple examples of line segments, but the code is deferred until Chapter 7. This section and the next section contain code samples with Matplotlib APIs that are not discussed; however, the code is straightforward, so you can infer its purpose. In addition, you can learn more about Matplotlib in Chapter 7 (which focuses on data visualization) or read a short online tutorial for more details.
Listing 2.20 displays the content of np_plot.py that illustrates how to plot multiple points on a line in the plane.
LISTING 2.20: np_plot.py
import numpy as np import matplotlib.pyplot as plt x = np.random.randn(15,1) y = 2.5*x + 5 + 0.2*np.random.randn(15,1) plt.scatter(x,y) plt.show()
Listing 2.20 starts with two import statements, followed by the initialization of x as a set of random values via the NumPy randn() API. Next, y is assigned a range of values that consist of two parts: a linear equation with input...