Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. %matplotlib inline
  2.  
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. import pandas as pd
  6. from scipy import stats
  7.  
  8. # Initial Data
  9. 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])
  10. 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])
  11. e = 70939.0
  12.  
  13. # Calculate concentration, ln[CV], 1/[CV]
  14. CV_molar = absorbance/e
  15. CV_ln = np.log(CV_molar)
  16. #Calculate the equation of the trendline for ln[CV]
  17. line_fit = np.polyfit(time, CV_ln,1)
  18.  
  19. #Create trendline array
  20. trendline_2 = np.empty(CV_ln.size)
  21. for k in range(0, CV_ln.size):
  22.     trendline_2[k] = time[k]*line_fit[0]+line_fit[1]
  23. slope, intercept, r_value, p_value, std_err = stats.linregress(time, trendline_2)    
  24.  
  25. #PLOT
  26. fig= plt.figure(figsize = (9,5))
  27. ax = plt.axes()
  28.  
  29. ax.plot(time, CV_ln,'-', label = 'Data')
  30. ax.plot(time, trendline_2,'.', label = 'trendline')
  31.  
  32. ax.set(xlabel='Time', ylabel = 'ln[CV+]',title='ln[CV+] vs time')
  33.  
  34. 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)))
  35. ax.text(0, -15,'The R^2 value of the trendline is R^2 ={k}'.format(k= r_value**2))
  36. ax.legend(['Data', 'Trendline'])
  37.  
  38. fig.savefig('my_figure_2.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement