In this example, we are not plotting any graphs, just plotting cells to demonstrate how the GridSpecFromSubplotSpec() method is used:
- fig = plt.figure(figsize=(12,6), constrained_layout=True) defines and instantiates the figure object with constrained_layout set to True. It is important to set the constrained_layout flag to True here, otherwise, it will not recognize the fig.set_constrained_layout_pads() statement at the end of the code. This is a difference compared to tight_layout(), which works even without setting this flag to true at the time of figure instantiation, as we saw earlier.
- gs0 = GridSpec(1, 3, figure=fig) defines the structure of the grid in the figure. Here, we are defining three grids, all in one row: ...