Object-Oriented Approach Using Subplots
Using the functional approach of plotting in Matplotlib does not allow the user to save the plot as an object in our environment. In the object-oriented approach, we create a figure object that acts as an empty canvas and then we add a set of axes, or subplots, to it. The figure object is callable and, if called, will return the figure to the console. We will demonstrate how this works by plotting the same x and y objects as we did in Exercise 13.
Exercise 19: Single Line Plot using Subplots
When we learned about the functional approach of plotting in Matplotlib, we began by creating and customizing a line plot. In this exercise, we will create and style a line plot using the functional plotting approach:
- Save x as an array ranging from 0 to 10 in 20 linearly spaced steps as follows:
import numpy as np
x = np.linspace(0, 10, 20)
Save y as x cubed using the following:
y = x**3
- Create a figure and a set of axes as follows:
import matplotlib.pyplot as...