If I understand correctly, you would like (2 x 3) subplots, where the x-axes of each column are aligned.
You can adapt the same code to do so; sharex='col'
will share the x-axis per individual column, or alternatively sharex=True
will share the x-axis across all subplots:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y1 = np.sin(x) # Data for the top subplot
y2 = np.cos(x) # Data for the bottom subplot
fig, ax = plt.subplots(2, 3, figsize=(8, 6), sharex='col', gridspec_kw={"hspace": 0.4})
ax = np.ravel(ax) # flatten
for ii in range(3):
ax[ii].plot(x, y1, label="sin(x)", color="blue")
ax[ii + 3].plot((ii + 1) * x, (ii + 1) * y2, label="cos(x)", color="orange")
plt.show()