Để tăng khoảng cách dọc (vertical space) giữa subplots, dùng fig.subplots_adjust(hspace=1).
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.
- Điều chỉnh: fig.subplots_adjust(hspace=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(hspace=1)
plt.show()
Kết quả
