X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=ctest%2Fmatplotlib_fit_hist.py;fp=ctest%2Fmatplotlib_fit_hist.py;h=8601325e084943dc872e27511b67f2de1978c50c;hb=40bf66aba1eb110e45e3c01a2001428f6864f300;hp=0000000000000000000000000000000000000000;hpb=afa8f7f791bbefc676d7f344d7b4a655f7c29f47;p=unres.git diff --git a/ctest/matplotlib_fit_hist.py b/ctest/matplotlib_fit_hist.py new file mode 100755 index 0000000..8601325 --- /dev/null +++ b/ctest/matplotlib_fit_hist.py @@ -0,0 +1,47 @@ +#! /usr/bin/env python + +import matplotlib +#matplotlib.use('GTK') +matplotlib.use('Agg') +import matplotlib.pyplot as plt +import numpy as np +from scipy.optimize import curve_fit +from math import sqrt +import sys + +def prob_T(x,a): + g=np.float128(105.) + Tr=np.float128(300.) + return a * ( x**((g-2)/2) * np.exp( -g*x/(2*Tr) ) ) + +#x,y= np.loadtxt('1L2Y_L_GB000.stat',usecols=(0,10),skiprows=30,unpack=True) +#x,y= np.loadtxt('1L2Y_NH_GB000.stat',usecols=(0,11),skiprows=10000,unpack=True) +#x,y= np.loadtxt('1L2Y_B_GB000.stat',usecols=(0,10),skiprows=30,unpack=True) +if (sys.argv[1] == '1L2Y_NH_GB000.stat'): + x,y= np.loadtxt(sys.argv[1],usecols=(0,11),skiprows=10000,unpack=True) +else: + x,y= np.loadtxt(sys.argv[1],usecols=(0,10),skiprows=10000,unpack=True) + +h,bin=np.histogram(y,bins=50,density=True) + +plt.bar(bin[:-1], h, width = bin[2]-bin[1]) +plt.xlim(min(bin), max(bin)) +plt.ylim(0,max(h)) +plt.ylabel('probality') +plt.xlabel('temperature') + +center = (bin[:-1] + bin[1:]) / 2 +#print bin +#print center +popt, pcov = curve_fit(prob_T, center, h, p0=10E-107) +xfine = np.linspace(min(bin), max(bin), 100) +#print popt + +chi_squared = np.sum((prob_T(center, *popt)-h)**2) +print '%15.10f' % chi_squared + +#print xfine +#print prob_T(xfine,popt[0]) +plt.plot(xfine,prob_T(xfine,popt[0]),'-',c='red') +plt.savefig(sys.argv[1]+'.png') +#plt.show()