59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Mon May 14 10:36:29 2018
|
|
|
|
@author: Armando
|
|
"""
|
|
|
|
import numpy as np
|
|
from scipy.optimize import curve_fit
|
|
import matplotlib.pyplot as plt
|
|
ph_value = []
|
|
mean_value = []
|
|
ph_mean = [(3.90,0.346344),
|
|
(4.25,0.363523),
|
|
#(4.29,0.360404),
|
|
(4.73,0.3758),
|
|
(5.05,0.414726),
|
|
(5.60,0.48224),
|
|
(6.17,0.698967),
|
|
(6.70,0.88613),
|
|
(7.30,0.940673),
|
|
#(9.51,1.00209),
|
|
(10.78,0.987067),
|
|
(11.54,1)]
|
|
|
|
for e in range(len(ph_mean)):
|
|
ph_value.append(ph_mean[e][0])
|
|
mean_value.append(ph_mean[e][1])
|
|
|
|
def tanh_fit(x, a, b, c, d):
|
|
return a*(np.tanh(b*x+c)) + d
|
|
|
|
def inverse_tanhfit(y ,a ,b ,c ,d):
|
|
return (1/2*np.log((a+y-d)/(a-y+d))-c)/(b)
|
|
|
|
popt, pcov = curve_fit(tanh_fit, ph_value, mean_value ,bounds=([0,0,-15,0], [1., 2.,5,1.]))
|
|
fig = plt.figure()
|
|
plt.title('Normalized intensity in function of pH')
|
|
plt.xlabel('pH', color='plum')
|
|
plt.ylabel('Normalized intensity (I/I\u2080)', color='0.5') # grayscale color
|
|
plt.grid(b=True, which='major', color='k', linestyle='-')
|
|
plt.grid(b=True, which='minor', color='k', linestyle='--')
|
|
plt.plot(ph_value,mean_value, 'r.')
|
|
x_full = np.arange(-1,15,0.01)
|
|
y_full = np.arange(0,1,0.01)
|
|
plt.plot(x_full, tanh_fit(x_full, *popt), '--',color = 'black',label='fit: A=%.3f, B=%.3f, C=%.3f D=%.3f \n A*tanh(B*pH+C) + D' % tuple(popt))
|
|
#plt.plot(y_full, inverse_tanhfit(y_full, *popt), '--',color = 'blue')
|
|
#plt.plot(x_full,x_full,'-',color = 'red')
|
|
plt.legend(bbox_to_anchor=(0.40,0), loc=3, borderaxespad=0.)
|
|
|
|
plt.show()
|
|
|
|
x_min = 0
|
|
x_max = ph_mean[len(ph_mean)-1][0]
|
|
y_min = tanh_fit(x_min, *popt)
|
|
y_max = tanh_fit(x_max, *popt)
|
|
|
|
|
|
#del(ph_value,mean_value,x_full) |