File: smooth_splines.dem

package info (click to toggle)
gnuplot 6.0.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,940 kB
  • sloc: ansic: 95,319; cpp: 7,590; makefile: 2,470; javascript: 2,328; sh: 1,531; lisp: 664; perl: 304; pascal: 191; tcl: 88; python: 46
file content (85 lines) | stat: -rw-r--r-- 2,881 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Plot smoothing with 
# natural cubic splines (smooth csplines)
# weighted approximate cubic splines (smooth acsplines)
# Bezier curve (smooth bezier)
# 2D and 3D acspline examples

print "various splines for smoothing"

set title "cubic spline fit to data (no weights)"
set samples 300
set xlabel "Time (sec)"
set ylabel "Rate"
plot "silver.dat" t "experimental" w errorb, \
               ""  smooth csplines t "cubic smooth" lw 2

pause -1 "Now apply a smoothing spline, weighted by 1/rel error (-> return)"
set title "acsplines weighted by relative error"
# error is column 3; weight larger errors less
# start with rel error = 1/($3/$2)
S=1
plot "silver.dat" t "experimental" w errorb,\
               "" u 1:2:(S*$2/$3) smooth acsplines t "acspline Y/Z" lw 2

pause -1 "Make it smoother by changing the smoothing weights (-> return)"
set title "acsplines with increasing weight from error estimate"
plot "silver.dat" t "rate" w errorb,\
               "" u 1:2:($2/($3*1.e1)) sm acs t "acspline Y/(Z*1.e1)" lw 2,\
               "" u 1:2:($2/($3*1.e3)) sm acs t "         Y/(Z*1.e3)" lw 2,\
               "" u 1:2:($2/($3*1.e5)) sm acs t "         Y/(Z*1.e5)" lw 2

pause -1 "Accentuate the relative changes with logscaling on y"
set title "Same plot (various weighting) in log scale"
set logscale y
set grid x y mx my
replot

pause -1 "Now approximate the data with a bezier curve between the endpoints (-> return)"
set title "Bezier curve rather than cubic spline"
unset logscale y
plot "silver.dat" t "experimental" w errorb,\
               "" smooth sbezier t "bezier" lw 2

pause -1 "You would rather use log-scales ? (-> return)"
set title "Bezier curve with log scale"
set logscale y
replot

unset log
unset grid

pause -1 "Same thing in 3D - planar case"
set title "3D smooth acsplines (special case with curve in single plane)"
set key right top
set key title "\n\n"
set xrange [0:600]
set yrange [0:600]
set zrange [0:300]
set xyplane at 0
unset xtics
set ytics offset 0,-1
set ylabel  "Time" offset 0,-2

set view 89.9 ,90, 1.5,1.0
splot "silver.dat" using (1):1:2 t "rate" w errorb,\
               "" u (1):1:2:($2/($3*1.e1)) smooth acs t "acspline Y/(Z*1.e1)" lw 2,\
               "" u (1):1:2:($2/($3*1.e3)) smooth acs t "         Y/(Z*1.e3)" lw 2,\
               "" u (1):1:2:($2/($3*1.e5)) smooth acs t "         Y/(Z*1.e5)" lw 2

pause -1 "Same thing in 3D general case"
set title "3D acsplines (general case)\nNote much larger weight values needed"
set view 90,45,1.,1.5
unset xtics
unset ytics
unset xlabel
unset ylabel

W = 1.e7
set key title sprintf("\n\nW = %.2g", W)
splot "silver.dat" using 1:1:2 t "rate" w errorb,\
               "" u 1:1:2:(W * $2/($3*1.e1)) smooth acs lw 2,\
               "" u 1:1:2:(W * $2/($3*1.e3)) smooth acs lw 2,\
               "" u 1:1:2:(W * $2/($3*1.e5)) smooth acs lw 2

pause -1 "Hit return to continue"
reset