import os import sys import numpy as np import matplotlib.pyplot as plt def plot(file): print("Reading "+file+" ...") name = file.split('.')[0] try: f = open(file,"r") line = f.readline() element = line.split() resx = element[0]; resx = int(resx) resy = element[1]; resy = int(resy) List_x = np.empty([resx]) for i in range(resx): line = f.readline(); x=float(line) List_x[i] = x List_y = np.empty([resy]) for i in range(resy): line = f.readline(); y=float(line) List_y[i] = y Map = np.empty([resx, resy]) for j in range(resy): for i in range(resx): line = f.readline() Map[i,j] = float(line) line = f.readline() ; xlabel = line.strip() line = f.readline() ; ylabel = line.strip() line = f.readline() ; title = line.strip() f.close() except: return plt.imshow(Map.T, extent=(np.min(List_x),np.max(List_x),np.min(List_y),np.max(List_y)), origin='lower', cmap='hot') plt.colorbar() plt.contour(List_x, List_y, Map.T, 9, colors='k', alpha=0.2) plt.xlabel(xlabel,size=12) plt.ylabel(ylabel,size=12) plt.title(title,size=12) plt.savefig(name+".png") plt.show() if __name__ == "__main__": if len(sys.argv) > 1: file = sys.argv[1] else: file = 'all' if file == 'all': list_of_files = os.listdir('.') for file in list_of_files: if file.endswith(".dat"): plot (file) else: plot (file)