Search code examples
pythonmatplotlibplotgraph

Subplot four-pack under another subplot the size of the four-pack


I want to make a matplotlib figure that has two components:

  1. A 2x2 "four pack" of subplots in the lower half of the figure

  2. A subplot above the four pack that is the size of the four pack.

I have seen this answer where subplots can have different dimensions. How can that approach be tweaked when there are multiple columns and rows, however? Or is a completely different approach warranted?

My final figure should be arranged something like this:

big plot above four pack

If there is a straightforward way to have a left-right oritentation, shown below, that would be helpful, too.

big plot left of four pack


Solution

  • You can use plt.subplot_mosaic or GridSpec. Someone else can write an answer using GridSpec, but here is how you'd do it using subplot_mosaic.

    For the large plot on top and 4 below it:

    import matplotlib.pyplot as plt
    
    fig, axs_dict = plt.subplot_mosaic("AA;AA;BC;DE")
    

    If you want to put the large plot on the left and the four smaller on the right then just using this string: "AABC;AADE".