import os import sys import numpy as np import matplotlib.pyplot as plt def plot(file): print("Reading "+file+" ...") name = file.split('.')[0] f = open(file,"r") nplot = f.readline() ; nplot = -int(nplot) res = f.readline() ; res = int(res) List_x = np.empty([res, nplot]) List_y = np.empty([res, nplot]) for j in range(nplot): for i in range(res): line = f.readline() elements = line.split() x = elements[0] ; x=float(x) y = elements[1] ; y=float(y) List_x[i,j] = x List_y[i,j] = y line = f.readline() ; xlabel = line.strip() line = f.readline() ; ylabel = line.strip() line = f.readline() ; title = line.strip() f.close() colors = ['b', 'r' , 'darkviolet' , 'k', 'green', 'lightcoral', 'darkorange', 'gold'] linestyles = ['-', '--', '-.', ':'] # solid, dashed, dotdashed, dotted # linestyles = ['-', '--', '-.', (0,(3,3,1,3,1,3)), ':'] # solid, dashed, dotdashed, dotdotdashed, dotted for j in range(nplot): # plt.plot(List_x[:,j],List_y[:,j],linestyle=linestyles[j],color=colors[j],label="f"+str(j)) plt.plot(List_x[:,j],List_y[:,j],linestyle=linestyles[j],color=colors[j]) plt.xlabel(xlabel,size=12) plt.ylabel(ylabel,size=12) plt.title(title,size=12) plt.legend() 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)