Cycoe@Home

Gnuplot 绘图第七弹-Gnuplot 式编程与数据处理

目前为此,所有绘图相关的操作都已经介绍完毕,接下来来点高级的。

1. for 循环

set term pngcairo mono dashed enhanced
set rmargin at screen .8
set key right center at screen 1,.6
plot [0:3] for [n=1:10:2] besj0(n*x) title "J_0(".n."x)"
c7-for.png

2. a:b:c 三目运算符

set samples 2000
f(x) = x < 0? sin(x) : NaN
g(x) = x >= 0? exp(-x/5.)*sin(x) : NaN
plot [-20:20] f(x), g(x)
c7-multi-section.png

3. 平滑曲线

set samples 500
set key right top box
set xrange [0:2*pi]

set table '~/random.dat'
plot sin(x) + 0.5 * rand(0)
unset table

plot '~/random.dat' w l lw 0.5 title "Original",\
     '' smooth bezier lw 4 title "Bezier Smoothed"
c7-smooth.png

4. 拟合曲线

set key right top box
set xrange [0:2*pi]

f(x) = a * sin(b * x) + c
fit f(x) '~/random.dat' via a, b, c

plot '~/random.dat' w l lw 0.5 title "Original",\
     f(x) w l lw 4 title "Fit by Gnuplot"
c7-fit.png
Author: Cycoe (cycoejoo@163.com)
Date: <2020-05-07 Thu 20:48>
Generator: Emacs 29.1 (Org mode 9.6.6)
Built: <2024-01-27 Sat 21:20>