import matplotlib.pyplot as plt# 使用 subplots 函數創建一個 2x3 的子圖網格
fig, axs = plt.subplots(nrows=2, ncols=3, figsize=(16, 10)) # 調整 figsize 來改變圖像大小# 遍歷每個子圖,并繪制一些內容(這里只是簡單的示例)
for ax in axs.flat:ax.plot([1, 2, 3], [1, 4, 2])ax.set_xlabel('x-label')ax.set_ylabel('y-label')# ax.set_title('Title')# 如果你需要單獨訪問某個子圖,你可以使用索引,例如:
# axs[0, 0] 是第一行第一列的子圖
# axs[1, 2] 是第二行第三列的子圖# 你可以給特定的子圖添加不同的內容或樣式
axs[0, 0].set_title('Special Title')
axs[0, 0].plot([1, 2, 3], [3, 2, 1], 'r') # 紅色線條# 顯示圖像
plt.tight_layout() # 調整子圖參數,使之填充整個圖像區域
plt.show()