Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmerice/examples/Inverse_Methods/DATA/PlotHist.py
3206 views
1
import numpy as np
2
from pylab import genfromtxt;
3
from scipy.stats import norm
4
import matplotlib.pyplot as plt
5
6
fname="MacAyeal_VELOCITIES.txt"
7
mat = genfromtxt(fname);
8
9
fname="MacAyeal_VELOCITIES_NOISE.txt"
10
matn = genfromtxt(fname);
11
12
u=mat[:,2]-matn[:,2];
13
v=mat[:,3]-matn[:,3];
14
du=np.sqrt(u*u + v*v)
15
16
npoints=np.size(mat,0)
17
rms=np.sqrt(np.sum(u*u + v*v )/npoints)
18
print(rms)
19
20
# Fit a normal distribution to the data:
21
mu_u, std_u = norm.fit(u)
22
mu_v, std_v = norm.fit(v)
23
24
plt.subplot(1,3,1)
25
# Plot the histogram.
26
plt.hist(du , bins=25, normed=True, alpha=0.6, color='g')
27
title = "du"
28
plt.title(title)
29
30
plt.subplot(1,3,2)
31
# Plot the histogram.
32
plt.hist(u , bins=25, normed=True, alpha=0.6, color='g')
33
34
# Plot the PDF.
35
xmin, xmax = plt.xlim()
36
x = np.linspace(xmin, xmax, 100)
37
p = norm.pdf(x, mu_u, std_u)
38
plt.plot(x, p, 'k', linewidth=2)
39
title = "u: mu = %.2f, std = %.2f" % (mu_u, std_u)
40
plt.title(title)
41
42
plt.subplot(1,3,3)
43
# Plot the histogram.
44
plt.hist(v , bins=25, normed=True, alpha=0.6, color='g')
45
46
# Plot the PDF.
47
xmin, xmax = plt.xlim()
48
x = np.linspace(xmin, xmax, 100)
49
p = norm.pdf(x, mu_v, std_v)
50
plt.plot(x, p, 'k', linewidth=2)
51
title = "v: mu = %.2f, std = %.2f" % (mu_v, std_v)
52
plt.title(title)
53
54
plt.show()
55
56
57
58
59