matplotlib中在for中画出多张图

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

 

 

posted @ 2018-01-14 17:59  chen狗蛋儿  阅读(668)  评论(0编辑  收藏  举报