The purpose of using plt.figure()
is to create a figure object.
The whole figure is regarded as the figure object. It is necessary to explicitly use plt.figure()
when we want to tweak the size of the figure and when we want to add multiple Axes objects in a single figure.
# in order to modify the size
fig = plt.figure(figsize=(12,8))
# adding multiple Axes objects
fig, ax_lst = plt.subplots(2, 2) # a figure with a 2x2 grid of Axes
plt.legend()是为了给图增加图例。