Plot components

In the prior examples using plt.plot(), we didn't have to create a Figure object—matplotlib took care of creating it for us in the background. However, as we saw with the example showing how bin size affects our output, anything beyond a basic plot will require a little more legwork, including creating a Figure object ourselves. The Figure is the top-level object for matplotlib visualizations. It contains the Axes objects, which themselves contain additional plot objects, such as the lines and ticks. In the case of subplots, the Figure object contains Axes objects with additional functionality.

We use the plt.figure() function to create Figure objects; these will have zero Axes objects until a plot is added:

>>> fig = plt.figure() ...

Get Hands-On Data Analysis with Pandas now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.