Ido Yehieli wrote:
>Hello,
> is it possible to use gnuplot's 'fit' command
>throw Gnuplot.py?
>
>
As the others have pointed out, you can call any gnuplot command from
Gnuplot.py. The other issue with "fit", however, is how do you get the
results of the fit back into Python? This is a problem because
Gnuplot.py doesn't have access to gnuplot's standard output.
Luckily this is easy--you write the parameters to a "parameters file"
(which fortuitously is valid python code) then read them back into
python. This is untested but should approximately work:
>>> g = Gnuplot.Gnuplot()
>>> open('fit.par', 'w').write('m=0\nb=0\n')
>>> g('fit m*x+b "data.in" via "fit.par"')
>>> g('update "fit.par" "fit2.par"') # saves fitted parameters to fit2.par
>>> parameters = {}
>>> execfile('fit2.par', globals(), parameters)
>>> print parameters
{'b': 1.5015, 'm': 1e-30}
>>> print parameters['m'], parameters['b']
1e-30 1.5015
In principle you could also parse "fit.log" to get the gory details
about the fit (standard errors, correlation matrix, etc).
Hope this helps,
Michael
--
Michael Haggerty
mh...@al...
|