79394736

Date: 2025-01-28 17:49:17
Score: 0.5
Natty:
Report link

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()

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Thijs