1
votes

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

1

1 Answers

1
votes

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.