I have a problem with a color bar in multiplot. The two plots are not aligned when I add the color bar. If I remove the color bar, the plots are aligned nicely.
How to resize the plots in multiplot? I just want to resize the width either lower or upper plot in oder to align the plots. Here is my code.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.gridspec as gridspec
fig = plt.subplots(2,figsize=(5, 8))
gs = gridspec.GridSpec(2, 1, height_ratios=[ 3,2],hspace=0.0)
ax1 = plt.subplot(gs[0])
ax2 = plt.subplot(gs[1])
xx = np.linspace(0,5,50)
yy = np.linspace(0,5,50)
X, Y = np.meshgrid(xx, yy)
T = X**2
norm = mpl.colors.Normalize(vmin=0,vmax=10)
pcm=ax1.pcolormesh(X,Y,T, norm =norm)
plt.colorbar(pcm, orientation="vertical", ax =ax1)
ax2.plot(xx, xx**2)
And, here is the result.