This section provides a brief introduction to plotting in pandas using matplotlib. The matplotlib API is imported using the standard convention, as shown in the following command:
In : import matplotlib.pyplot as plt
Series and DataFrame have a plot method, which is simply a wrapper around plt.plot. Here, we will examine how we can do a simple plot of a sine and cosine function. Suppose we wished to plot the following functions over the interval pi to pi:
- f(x) = cos(x) + sin (x)
- g(x) = cos (x) - sin (x)
This gives the following interval:
In : import numpy as np In : X = np.linspace(-np.pi, np.pi, 256,endpoint=True) In : f,g = np.cos(X)+np.sin(X), np.sin(X)-np.cos(X) In : f_ser=pd.Series(f) ...