'How to customize subplot horizontal space?

I'm trying to create a heatmap. I want there to be a single column heatmap with one palette, and then immediately next to it, I'd like another heatmap. This is my code and what I've come up with so far, but I don't know how to get rid of all that whitespace in the middle? I can't seem to make this work. I know about subplots and columns/rows, but I don't know how to make it so that it's not equally divided (for example, 2 columns don't need equal amount of horizontal space). Any advice or examples would be appreciated.

#figure details
    fig = plt.figure(constrained_layout=True, figsize=(28,12))
    # fig.tight_layout()
    fig.suptitle('Most Common First & Second Letter Combinations', fontsize=28, va = 'top', ha = 'center')
    
    #most common first letters
    ax1 = fig.add_subplot(1,2,1)
    ax1 = sns.heatmap(df, annot=True, square=True, fmt=".2f", cmap='YlOrBr', xticklabels=False, vmin=0.0, vmax=0.2,
                      cbar_kws={'shrink': 1, 'location': 'left', 'pad':0.03})
    ax1.set_yticklabels(ax1.get_yticklabels(), rotation = 0, fontsize = 16)
    ax1.set_xticklabels(ax1.get_xticklabels(), rotation = 0, fontsize = 16)
    ax1.set_aspect('equal')
    
    #most common following letters
    ax2 = fig.add_subplot(1,2,2)
    ax2 = sns.heatmap(df2, annot=data2l, square=True, fmt = '', cmap='Blues', xticklabels=False, yticklabels=False, vmin=0.0, vmax=0.25,
                      cbar_kws={'shrink': 1, 'pad': 0.03})
    ax2.set_yticklabels(ax2.get_yticklabels(), rotation = 0, fontsize = 16)
    ax2.set_aspect('equal')
    
    plt.show()

That yields the following plot: Two heatmaps that are very far apart



Solution 1:[1]

You could try:

fig.tight_layout()

And ajust the spacing using the pad variable.

Documentation: https://matplotlib.org/3.5.1/api/_as_gen/matplotlib.pyplot.tight_layout.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samuel Brum Martins