Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %matplotlib inline
- import matplotlib.pyplot as plt
- import numpy as np
- import pandas as pd
- from scipy import stats
- # Initial Data
- time = np.array([0.008333334,0.508333325,1.008333325,1.508333325,2.008333445,2.508333445,3.008333445,3.508333445,4.008333206,4.508333206,5.008333206,5.508333206,6.008333206,6.508333206,7.008333206,7.508333206,8.008333206])
- absorbance = np.array([0.417830259,0.346029699,0.290778458,0.243839279,0.205080524,0.171536624,0.144038409,0.120138422,0.101258248,0.083564349,0.069462888,0.059087373,0.04753048,0.039430205,0.032463193,0.027355824,0.021077819])
- e = 70939.0
- # Calculate concentration, ln[CV], 1/[CV]
- CV_molar = absorbance/e
- CV_ln = np.log(CV_molar)
- #Calculate the equation of the trendline for ln[CV]
- line_fit = np.polyfit(time, CV_ln,1)
- #Create trendline array
- trendline_2 = np.empty(CV_ln.size)
- for k in range(0, CV_ln.size):
- trendline_2[k] = time[k]*line_fit[0]+line_fit[1]
- slope, intercept, r_value, p_value, std_err = stats.linregress(time, trendline_2)
- #PLOT
- fig= plt.figure(figsize = (9,5))
- ax = plt.axes()
- ax.plot(time, CV_ln,'-', label = 'Data')
- ax.plot(time, trendline_2,'.', label = 'trendline')
- ax.set(xlabel='Time', ylabel = 'ln[CV+]',title='ln[CV+] vs time')
- ax.text(0, -14.8,'The equation of the trendline is y={a}x - {b}'.format(a=round(line_fit[0],2), b=0-round(line_fit[1],2)))
- ax.text(0, -15,'The R^2 value of the trendline is R^2 ={k}'.format(k= r_value**2))
- ax.legend(['Data', 'Trendline'])
- fig.savefig('my_figure_2.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement