1

I have created my first graph based on the input on stackoverflow. So my code is,

set title "Approximation Graph"
set term png
set output 'plot.png'
f0_h(x) = a0_h * x**2 + b0_h * x + c0_h
fit f0_h(x) 'clk0_h' via 'clk0_h_c'
f1_h(x) = a1_h * x**2 + b1_h * x + c1_h
fit f1_h(x) 'clk1_h' via 'clk1_h_c'
f0_s(x) = a0_s * x**2 + b0_s * x + c0_s
fit f0_s(x) 'clk0_s' via 'clk0_s_c'
f1_s(x) = a1_s * x**2 + b1_s * x + c1_s
fit f1_s(x) 'clk1_s' via 'clk1_s_c'

set style data lines
plot "clk0_h" using 1:2, f0_h(x), "clk1_h" using 1:2, f1_h(x), "clk0_s" using 1:2, f0_s(x), "clk1_s" using 1:2, f1_s(x)

The graph is:

enter image description here

So I have major and minor question.

Major : is it possible to determine coefficient using gnuplot. As of now, I determine manually. (some reason, I can not use numpy in python for determine coefficient)

Minor : Can anyone refer me line property. 1) increase line width 2) change color 3) add a title for each line (to differentiate if they have same color) 4) like I should have 8 line but some are overwrite

Christoph
  • 47,569
  • 8
  • 87
  • 187
user765443
  • 1,856
  • 7
  • 31
  • 56

1 Answers1

1

Concerning your first question: This is what fit actually does. In your script, by using via 'file.par' you only set starting values and specify the variables which are to be used for the fitting.

Just try the following:

f0_h(x) = a0_h * x**2 + b0_h * x + c0_h
fit f0_h(x) 'clk0_h' via a0_h, b0_h, c0_h

and see, if the coefficients come out well. By default, the starting values are assumed to be 1. If it doesn't work out, you may need to set the correct order of magnitude (set e.g. a0_h = 10 before fitting).

Regarding the minor stuff, use linewidth, linecolor etc. for the line properties. To specify the title, use title :).

You can define a linestyle for each function/data combination and use the line for the fit, and points for the data:

set style line 1 linecolor rgb 'red' linewidth 2 pointtype 4 linetype -1
set style line 2 linecolor rgb '#ff7700' pointtype 7 linetype 2
...

In this case, if you specify linecolor and linetype, the first determines the color, the second one the dash pattern (it the terminal supports it, see Gnuplot line types).

For the plotting, with the above kind of line style definitions, use e.g.

set style data points
set style func lines # these two settings are default

plot "clk0_h" using 1:2 linestyle 1 title 'clk0_h, data', \
     f0_h(x) linestyle 1 title 'clk0_h, fit'
...

And you should consider using the pngcairo terminal, which creates much nicers graphics. Or, preferably, use a vector-based terminal, like pdfcairo.

Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Thanks a lot for reply for both question. For First question, I have x and y data point and need to determine a,b,c for quadratic equation. As per your suggestion, By default it is 1 or change a0_h value. is it possible to use any function of gnuplot to determine a0_h,b0_h,c0..... – user765443 Oct 18 '13 at 02:40
  • @AbhishekGoswami Yes, basically you can define any function which use theses coefficients. But for a more complicated function it may happend, that the fit doesn't have good convergence, that you must use better starting values. But basically you can use anything which returns a number. – Christoph Oct 18 '13 at 06:37
  • Thanks for your input. One more minor question. When I run gnuplot, it generate fit.log and generate similar message in stdout. is it possible to hide this message. As it is kind of confusion for end user. if They need detail They can look into fit.log – user765443 Oct 18 '13 at 06:53
  • @AbhishekGoswami Use `set fit quiet`, which is available since 4.6.0 – Christoph Oct 18 '13 at 06:58
  • Thanks a lot for your prompt responce – user765443 Oct 18 '13 at 07:07