Yes that is a suitable approach.
First some code to get you going (I tweaked your code):
import matplotlib.pyplot as plt
import numpy as np
import math
figure = plt.figure()
def Gaussian(x, Geoms):
# Geoms is a n X 3 array:
# Position, Amplitude, FWHM
#Geoms = [[2,.00001,3][1,17,.2]]
Position = Geoms[:, 0]
Amplitude = Geoms[:, 1]
FWHM = Geoms[:, 2]
y = np.zeros(x.shape)
for i in np.arange(0, Amplitude.shape[0]):
g = Position[i]; q = (x-g); v = FWHM[i]
q = q*q; v = v*v
y += (Amplitude[i] * np.exp(-q/(v*np.sqrt(2))))
return y
count = 0
with open("chan.txt", "r") as metapart:
for line in metapart:
if "&END" in line:
break
count = count + 1
print count
print metapart.next()
metapart.seek(0)
data = np.genfromtxt(metapart, skiprows=11)
print data
metapart.close()
x_data = data[:,0]
y_data = data[:,1]
# Build several gaussian peaks.
FWHM = 0.25
Geoms = np.array([[24.48, 922, FWHM], [28.35, 644, FWHM]])
y_fit = Gaussian(x_data, Geoms)
# I recommend keeping your data in its original form. Only display it logarithmically if you want.
plt.semilogy(x_data,y_data, 'r', x_data, y_fit, 'b')
# And you may want to control the plot range.
plt.axis([0,100, 1,1000])
plt.show()
I added a function I wrote a while ago called Gaussian that, generates your peaks. Sorry it isn't better commented, but it should be pretty straightforward to use. It requires numpy inputs.
Second, I removed your for loop for truncating the data at 0. (You can look into numpy.clip() in the future if you want to do that). I recommend leaving your data in the original format, and only plot it logarithmically. This is especially true if you are doing fits, since otherwise you have to write a log_gaussian function, etc., and it gets confusing.
Here, I just dropped in the first two gaussians by hand. Of course, you can drop in the rest by hand and tweak the values until they are as accurate as the uncertainty imposed by the digitization of your data within a few minutes. If you're doing this once, that's what I'd do. But if you are doing this more than once, or you have more complicated shapes, I would spend the time to learn the SciPy optimize module. You probably want to start with the SciPy tutorial. Using ScyPy optimize has a longer runway, but it pays off with interest and dividends, and many stock splits.
Enjoy!