用Python批量绘制二维矩阵
import numpy as np from matplotlib import pyplot as plt import matplotlib as mpl import glob def create_4_colorMap(): #colors= ['blue','cyan','green','pink','magenta','purple','gold','red'] colors= ['gray','yellow','orange','red'] discmap = mpl.colors.ListedColormap(colors) return discmap def create_8_colorMap(): #colors= ['blue','cyan','green','pink','magenta','purple','gold','red'] colors= ['blue','green','pink','magenta','orange','yellow','red', 'black'] discmap = mpl.colors.ListedColormap(colors) return discmap dismap_4 = create_4_colorMap() npyRows = 128 npyCols = 128 plt.figure(figsize=(npyRows, npyCols), dpi=1) plt_img=plt.imshow(np.random.rand(npyRows, npyCols), vmin=0, vmax=9, cmap=dismap_4, aspect="auto") plt.axis('off') plt.gca().xaxis.set_major_locator(plt.NullLocator()) plt.gca().yaxis.set_major_locator(plt.NullLocator()) plt.subplots_adjust(top=1, bottom=0, right=1, left=0) plt.margins(0,0) #plt.colorbar() def showNpy2dFacies(npy2dFile): dat = np.load(npy2dFile) print(npy2dFile) #print(dat.shape) plt.imshow(dat,vmin=0, vmax=3, cmap=dismap_4) plt.savefig(npy2dFile.replace('.npy','.png')) #plt.show() #plt.close() def showNpy2dSeis(npy2dFile): dat = np.load(npy2dFile) print(npy2dFile) #print(dat.shape) plt.imshow(dat, cmap='seismic') plt.savefig(npy2dFile.replace('.npy','.png')) #plt.show() #plt.clf() def showNpyFaciesBatch(): for i in range(1,1420): npyFile="samples/facies_{0}.npy".format(i) showNpy2dFacies(npyFile) def showNpySeisBatch(): for i in range(750,1420): npyFile="samples/seismic_{0}.npy".format(i) showNpy2dSeis(npyFile) if __name__ == "__main__": #showNpyFaciesBatch() showNpySeisBatch()