Path: blob/devel/elmerice/examples/Inverse_Methods/DATA/PlotHist.py
3206 views
import numpy as np1from pylab import genfromtxt;2from scipy.stats import norm3import matplotlib.pyplot as plt45fname="MacAyeal_VELOCITIES.txt"6mat = genfromtxt(fname);78fname="MacAyeal_VELOCITIES_NOISE.txt"9matn = genfromtxt(fname);1011u=mat[:,2]-matn[:,2];12v=mat[:,3]-matn[:,3];13du=np.sqrt(u*u + v*v)1415npoints=np.size(mat,0)16rms=np.sqrt(np.sum(u*u + v*v )/npoints)17print(rms)1819# Fit a normal distribution to the data:20mu_u, std_u = norm.fit(u)21mu_v, std_v = norm.fit(v)2223plt.subplot(1,3,1)24# Plot the histogram.25plt.hist(du , bins=25, normed=True, alpha=0.6, color='g')26title = "du"27plt.title(title)2829plt.subplot(1,3,2)30# Plot the histogram.31plt.hist(u , bins=25, normed=True, alpha=0.6, color='g')3233# Plot the PDF.34xmin, xmax = plt.xlim()35x = np.linspace(xmin, xmax, 100)36p = norm.pdf(x, mu_u, std_u)37plt.plot(x, p, 'k', linewidth=2)38title = "u: mu = %.2f, std = %.2f" % (mu_u, std_u)39plt.title(title)4041plt.subplot(1,3,3)42# Plot the histogram.43plt.hist(v , bins=25, normed=True, alpha=0.6, color='g')4445# Plot the PDF.46xmin, xmax = plt.xlim()47x = np.linspace(xmin, xmax, 100)48p = norm.pdf(x, mu_v, std_v)49plt.plot(x, p, 'k', linewidth=2)50title = "v: mu = %.2f, std = %.2f" % (mu_v, std_v)51plt.title(title)5253plt.show()545556575859