Creating Complex Layouts with GridSpec

In this lesson, we will learn how to use GridSpec to create complex layouts for a figure.

What is GridSpec?

Despite the implications of its name, GridSpec does not affect the grid. In actuality, it is used to customize the layout of a figure. In the previous lesson, we learned how to create grid-shaped subplots by calling subplots(). Since subplots are easy to use, why do we need GridSpec?

Although subplots() is a useful feature, GridSpec allows us to have more control over the placement and shape of our subplots. GridSpec makes it much easier to control the margins of the plots and the spaces between the subplots.

For each subplot, we can arbitrarily allocate a rectangular area as needed. Unlike subplots, plots created from GridSpec can have different sizes. In order to control these varying sizes, we need to create each axes manually, one by one.