Path: blob/devel/elmerice/examples/Inverse_Methods/SCRIPTS/PlotHist.py
3206 views
#1# Make histogram plots from inverse methods results2# Give a file that contains x y uobs vobs umod vmod3#4#5import numpy as np6from pylab import genfromtxt;7from scipy.stats import norm8import matplotlib.pyplot as plt9import sys1011try:12sys.argv[1]13except:14print('error: ')15print(' provide a file name as argument')16print(' must contain x y uobs vobs umod vmod')17exit()1819fname=sys.argv[1]20try:21mat = genfromtxt(fname);22except:23print('error: ')24print(' couldn t open %s'%(fname))252627# Get Delta U and Delta V28u=mat[:,2]-mat[:,4];29v=mat[:,3]-mat[:,5];30du=np.sqrt(u*u + v*v)3132# Compute RMS33npoints=np.size(mat,0)34rms=np.sqrt(np.sum(u*u + v*v )/npoints)35print(rms)3637# Fit a normal distribution to the data:38mu_u, std_u = norm.fit(u)39mu_v, std_v = norm.fit(v)4041plt.subplot(1,3,1)42# Plot the histogram.43plt.hist(du , bins=25, normed=True, alpha=0.6, color='g')44title = "du"45plt.title(title)4647plt.subplot(1,3,2)48# Plot the histogram.49plt.hist(u , bins=25, normed=True, alpha=0.6, color='g')5051# Plot the PDF.52xmin, xmax = plt.xlim()53x = np.linspace(xmin, xmax, 100)54p = norm.pdf(x, mu_u, std_u)55plt.plot(x, p, 'k', linewidth=2)56title = "u: mu = %.2f, std = %.2f" % (mu_u, std_u)57plt.title(title)5859plt.subplot(1,3,3)60# Plot the histogram.61plt.hist(v , bins=25, normed=True, alpha=0.6, color='g')6263# Plot the PDF.64xmin, xmax = plt.xlim()65x = np.linspace(xmin, xmax, 100)66p = norm.pdf(x, mu_v, std_v)67plt.plot(x, p, 'k', linewidth=2)68title = "v: mu = %.2f, std = %.2f" % (mu_v, std_v)69plt.title(title)7071plt.show()727374757677