I am struggling finding a way to keep the projection of the image completely aligned to the image (as in the figure below) but at the same time reducing their dimension so that the image take most of the figure space.
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.image as mpimg
import numpy as np
from skimage import data
img = data.coins()
h,w = img.shape
ratio = h/w
fig = plt.figure(figsize=(8, 8))
gs = gridspec.GridSpec(2, 2, width_ratios=[1*ratio, 1], height_ratios=[1/ratio, 1])
ax_center = plt.subplot(gs[1, 1])
ax_center.imshow(img)
ax_left = plt.subplot(gs[1, 0])
ax_left.set_title('Left Plot')
ax_left.plot(-img.mean(axis=1),range(img.shape[0]))
ax_top = plt.subplot(gs[0, 1])
ax_top.plot(img.mean(axis=0))
ax_top.set_title('Top Plot')
plt.tight_layout()
plt.show()
Basically I would like the top plot to have a smalle height and the left top to have a smaller width keeping them perfectly aligned to the image.

You could do the following (by setting
aspect="auto"the image could potentially become distorted, so in the example below I've tweaked the figure size appropriately to account for that):This produces: