1. 程式人生 > >matplotlib中在for中畫出多張圖

matplotlib中在for中畫出多張圖

num () randint nump pict mat inf col int

import matplotlib.pyplot as plt
import numpy as np


fig, axes = plt.subplots(2, 2)
def showim():
    for i in range(2):
        for j in range(2):
            axes[i,j].plot(np.random.randint(10,size=10))
            # 為每個子圖添加標題
            axes[i,j].set_title("picture "+str(i)+" "+str(j))
            fig.tight_layout()
            
# 為每個子圖去掉坐標軸刻度 axes[i,j].set_xticks([]) axes[i,j].set_yticks([]) showim() plt.show()

技術分享圖片

matplotlib中在for中畫出多張圖