WHAT IS MATPLOTLIB?
Matplotlib is a plotting library that supports NumPy, SciPy, and toolkits such as wxPython (among others). Matplotlib supports only version 3 of Python: support for version 2 of Python was available only through 2020. Matplotlib is a multi-platform library that is built on NumPy arrays.
The plotting-related code samples in this chapter use pyplot, which is a Matplotlib module that provides a MATLAB-like interface. Here is an example of using pyplot to plot a smooth curve based on negative powers of Euler’s constant e:
import matplotlib.pyplot as plt import numpy as np a = np.linspace(0, 10, 100) b = np.exp(-a) plt.plot(a, b) plt.show()
Keep in mind that the code samples that plot line segments assume that you are familiar with the equation of a (non-vertical) line in the plane: y = m*x + b, where m is the slope and b is the y-intercept.
Furthermore, some code samples use NumPy APIs, such as np.linspace(), np.array(), np.random.rand(), and np.ones(), which...