2
votes

I got a data that has a lot of data points, no definite equation or fit just a lot of spikey data, I just wanna connect all those and create a smooth graphs using Gnuplot however, nothing could make the plot as smooth as those produced by MS Excel. How do I create an Excel-like smooth plot?

Gnuplot settings I used:

set terminal postscript eps enhanced font "FreeSerif,14" size 3.0in,1.7in
set output 'fig4a.eps'
set encoding iso_8859_1
set border linewidth .5
set xlabel '{/FreeSerif-BoldItalics d} {/FreeSerif-Bold ({\305})}'
set ylabel '{/FreeSerif-Bold {/Symbol D}{/FreeSerif-Bold C}_q (e/V)}'
set xrange [-8:8]
set xtics -8,2,8
set mxtics 2
set yrange [0:0.3]
set ytics 0,0.1,0.3
set mytics 2
set key at 1.42,-0.24 reverse
set style line 1 linewidth 0.5
plot for [n=2:4] 'fig4a.dat' u 1:n smooth cspline frequency w lines ls 1    
replot
quit

These are the plots I have (the designs were a bit different, as I am still resolving smoothing problem) Excel Excel smooth plot

Gnuplot (spline, cspline, mcspline (each of these produce similar output)) enter image description here

Some Selected Data points

Using: plot 'fig4a.dat' u 1:4 smooth cspline notitle w lines ls 1

Output: enter image description here

Data points:

-8.09808994 -3.53E-07
-7.99108994 -1.02E-05
-7.88508994 -0.000162606
-7.77908994 -0.001377785
-7.67308994 -0.00552213
-7.56708994 -0.00499697
-7.46108994 0.0326345
-7.35408994 0.1168893
-7.24808994 0.186241
-7.14208994 0.205997
-7.03608994 0.191836
-6.93008994 0.151735
-6.82308994 0.106245
-6.71708994 0.086542
-6.61108994 0.104821
-6.50508994 0.155378
-6.39908994 0.192769
-6.29208994 0.17085
-6.18608994 0.133063
-6.08008994 0.093566
-5.97408994 0.091761
-5.86808994 0.171249
-5.76108994 0.20373
-5.65508994 0.139635
-5.54908994 0.117342
-5.44308994 0.142744
-5.33708994 0.111295
-5.23008994 0.047449
-5.12408994 0.017428002
-5.01808994 0.025381005
-4.91208994 0.07760701
-4.80608994 0.177550019
-4.69908994 0.221490023
-4.59308994 0.130530012
-4.48708994 0.022438001
-4.38108994 -0.004862101
-4.27508994 0.022498
-4.16908994 0.079377
-4.06208994 0.14604
-3.95608994 0.19269
-3.85008994 0.19097
-3.74408994 0.125244
-3.63808994 0.05851
-3.53108994 0.053151
-3.42508994 0.063857
-3.31908994 0.05646
-3.21308994 0.05375
-3.10708994 0.06817
-3.00008994 0.081894
-2.89408994 0.070248
-2.78808994 0.055941
-2.68208994 0.0445004
-2.57608994 0.029018
-2.46908994 0.034651
-2.36308994 0.05154
-2.25708994 0.051322
-2.15108994 0.053645993
-2.04508994 0.079479713
-1.93808994 0.110223123
-1.83208994 0.12952024
-1.72608994 0.123183
-1.62008994 0.100336
-1.51408994 0.0878377
-1.40708994 0.08143
-1.30108994 0.11223
-1.19508994 0.167822
-1.08908994 0.157034
-0.98308994 0.107838
-0.87708994 0.09736
-0.77008994 0.10481
-0.66408994 0.12359
-0.55808994 0.17554
-0.45208994 0.21844
-0.34608994 0.20774
-0.23908994 0.169731
-0.13308994 0.143784
-0.02708994 0.134956
0.07891006  0.136358
0.18491006  0.115993
0.29191006  0.1022772
0.39791006  0.130636
0.50391006  0.137051
0.60991006  0.108013
0.71591006  0.108763
0.82291006  0.147532
0.92891006  0.1658
1.03491006  0.160103
1.14091006  0.1589476
1.24691006  0.1353571
1.35391006  0.09032325
1.45991006  0.05464951
1.56591006  0.03587591
1.67191006  0.031322905
1.77791006  0.021403117
1.88491006  0.00489071
1.99091006  0.002355969
1
Several things: your plot line uses wrong syntax, should be plot for [n=2:4] 'fig4a.dat' u 1:n smooth cspline ls 1 w lines. And how can we know how the plot generated by Excel looks like? Please show an example. And try different interpolations like smooth cspline, smooth bezier, smooth mcspline.Christoph
hi @Christoph its just typo. yhea, cspline does not do smoothing, bezier reduced my data points into i think into 4 degree polynomial, mcspline does not do it either.Jones G
cspline does smoothing, but without seeing any more concrete examples (data, current results, Excel comparison) it is quite pointless to go on guessing...Christoph
Ok, still, without having a minimal but full working example which includes a minimal excerpt of the data file (enough to show that the smoothing fails), and a minimal script (only one plot line, no labels etc), I can only guess. As you can see in my answer to smooth peaks in gnuplot, all of the three smoothing options work fine, unless you are hitting some oddities with e.g. your data file format which I cannot know.Christoph
I know gnuplot cspline, bezeir does smoothing, I have tried it in some few data points before, it works ok, but not on this one, I can't do any smoothing. I will update my post to show show some data points.Jones G

1 Answers

3
votes

You can set the number of points to show in a spline with

set sample 1000