Để tăng khoảng cách ngang (horizontal space) giữa các subplot, dùng fig.subplots_adjust(wspace=1) (cần tắt autolayout/tight_layout).
Các bước
- Thiết lập figure size và autolayout.
- Tạo dữ liệu x, y.
- Tạo lưới subplot 2x2 bằng plt.subplots(nrows=2, ncols=2).
- Điều chỉnh: fig.subplots_adjust(wspace=1).
- Hiển thị bằng show().
Ví dụ
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2)
fig.subplots_adjust(wspace=1)
plt.show()
Kết quả
