옵션 |
|
import openpyxl import matplotlib.pyplot as plt import numpy as np from scipy.optimize import curve_fit #엑셀 파일을 불러옴. excel_result = openpyxl.load_workbook("C:\\Dev\\GraduationThesis\\result_1.xlsx") sheet_result = excel_result['Sheet2'] def sheet_value(r, c): #셀 값을 불러옴 return sheet_result.cell(row=r, column=c).value def gauss_func(x, a, b, c): #gaussian function return a*np.exp(-(x-b)**2/(2*c**2)) def lorenzian_func(x, x0, r): #lorenzian function return (r**2/(((x-x0)**2)+r**2))/(np.pi*r) from scipy.misc import factorial def poisson_func(x, lamb): #poisson fuction return (lamb**x/factorial(x)) * np.exp(-lamb) index = 1 list_Hz = list() list_Mag = list() #엑셀의 각 데이터를 리스트 형식으로 바꿈 while True: if sheet_value(index, 1) == None: break; list_Hz.append(sheet_value(index, 1)) list_Mag.append(sheet_value(index, 2)) index += 1 #리스트를 array형태로 바꿈 x = np.array(list_Hz) y = np.array(list_Mag) #초기값 init = [10] #fitting popt, pcov = curve_fit(gauss_func, x, y) plt.plot(x, y, linewidth=2, color='blue') plt.plot(x, gauss_func(x, *popt), color = 'green', linewidth=2) plt.legend(['Data', 'fitting'], loc=2) plt.show() excel_result.close() |