How to plot a function of an imported data in gnuplot?

橙三吉。 提交于 2019-12-22 05:46:29

问题


If I have a file of several data points. How can I plot a function of them? For example, suppose I have a file of to columns x and y and I want to plot sin(y) as a function of 1/x.


回答1:


Try this:

plot "-" u (1/$1):(sin($2)) w l
    2.00000    0.16104
    3.00000    0.15604
    4.00000    0.40055
    5.00000    0.09972
    e

Or when not using data files make use of the parametric mode, which is described here

EDIT

With this data file Data.csv:

 0.00000    0.33371
 1.00000    0.13034
 2.00000    0.16104
 3.00000    0.15604
 4.00000    0.40055
 5.00000    0.09972
 6.00000    0.25204
 7.00000   -0.34172
 8.00000   -0.04733
 9.00000   -0.27211
10.00000    0.10229
11.00000   -0.30608
12.00000    0.11006
13.00000   -0.44390
14.00000   -0.16963
15.00000    0.03208
16.00000    0.32431
17.00000    0.15424
18.00000    0.16468
19.00000    0.24410
20.00000    0.34961

I can run this script:

f(x) = kappa*x**2

fit f(x) "Data.csv" u (log($1)):(sin($2)) via kappa
plot "Data.csv" u 1:(sin($2)), f(x) w l

Which gives me this plot:

Granted, the fitting does not make any sense at all^^.

Are you maybe missing some brackets in your fit?!



来源:https://stackoverflow.com/questions/6938703/how-to-plot-a-function-of-an-imported-data-in-gnuplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!