gnuplot 的使用

来源:互联网 发布:巅峰霍华德身体数据 编辑:程序博客网 时间:2024/06/05 09:12

plot 命令的格式:

Syntax:       plot {[ranges]}            {[function] | {"[datafile]"       {datafile-modifiers}}}            {axes [axes] } { [title-spec] } {with [style] }            {, {definitions,} [function] ...}

plot 一个数据文件。 例子文件 a.txt 的内容的一部分。

1 611738 581056 593414 583590 502984 5538132 661569 548566 556251 503663 461451 5072953 723006 558036 518351 461444 429248 4640064 748299 579828 510268 432925 403245 4442335 770639 630340 558121 428781 409407 4475176 773501 663703 580150 430565 414668 4541687 773358 680100 602547 429561 415999 4594558 772250 693620 616986 424956 416455 4616359 767792 714011 642304 419132 413608 46474710 760577 729287 666633 410204 416556 464428...
gnuplot> plot "data.txt" using 1:2

using 1:2 表示用第一列表示 x 坐标,用第二列表示 y 坐标。

gnuplot> plot [0:100] [0:800000] "a.txt" using 1:2

可以指明 x 坐标的范围是 0 到 100 , y 坐标的范围是 0 到 800000 。下面的办法一样可以实现相同的功能。

gnuplot> set xrange [0:100]gnuplot> set yrange [0:800000]gnuplot> plot "a.txt" using 1:2

可以用 title 来指明一个曲线的名字。

gnuplot> plot "a.txt" using 1:2 title "sample curve" ;

可以用

gnuplot> plot "a.txt" using 1:2 with lines # 用线条画图gnuplot> plot "a.txt" using 1:2 with points # 用点画图gnuplot> plot "a.txt" using 1:2 with linespoints # 用点线结合的方式画图

下面的例子可以同时显示两条曲线,分别用点和线的方式。

gnuplot> plot sin(x) with lines title 'Sine Function', \     tan(x) with points title 'Tangent'

下面的例子可以用不同的颜色显示线。

gnuplot> plot sin(x) with lines linetype 1
下面的例子说明如何指定线条的宽度。
gnuplot> plot sin(x) with lines linewidth 6
类似可以用 pointtype 和 pointsize 指定点的颜色和大小。

可以用 test 命令查看所有支持的 linetype, linewidth, pointtype, pointsize。

也可以用下面的办法指定 line 和 point 的样子。

gnuplot> plot "a.txt" using 1:2 with linespoints linestyle 1gnuplot> set style line 1 linetype 2 linewidth 1 pointsize 2 pointtype 6gnuplot> replotgnuplot> set style line 1 linetype 2 linewidth 1 pointsize 2 pointtype 4gnuplot> replotgnuplot> set style line 1 linetype 2 linewidth 1 pointsize 2 pointtype 11gnuplot> replot
下面的例子说明如何指明 X Y 坐标的名称。
gnuplot> set xlabel "time(t)"gnuplot> set ylabel "A"gnuplot> plot sin(x)
<!—左面的坐标叫做 y1 , 右边的坐标叫 y2 , 上面的坐标叫做 x2, 下面的坐标叫做 x1 可以用 axes 来指明显示哪些坐标轴。—>

可以用下面的命令处理边框 。

gnuplot> unset border # 没有边框gnuplot> set border 1 linetype 2 # 下面的边框用 linetype 2gnuplot> replotgnuplot> set border 2 linetype 3 # 左面的边框用 linetype 3gnuplot> replotgnuplot> set border 3 linetype 3 # 下面和左面的边框用 line type 3
border 后面的数字是一个12个bit 的整数,每一位bit 表示一个边框。 于是 1 ,2, 4, 8 分别对应下,左,上,右边框。

可以用 set grid 来控制背景栅格。查看帮助 help set grid

gnuplot> set gridgnuplot> unset grid

可以用 set key 来控制曲线名称的摆放位置。查看帮助 help set key

gnuplot> plot sin(x) title "Sine X"gnuplot> set key top leftgnuplot> replot

可以用下面的办法增加一个标记。查看帮助 help set arrow , help set label

gnuplot> set label 1 "Peak" at -5,0.8 rightgnuplot> set arrow 1 from -5,0.8 to -0.9,0.9 headgnuplot> replot

可以用下面的办法给图增加一个标题。查看帮助 help set title

gnuplot> set title "My Figure 1"gnuplot> replot

可以用下面的办法控制坐标的刻度的表示。查看帮助 help set xtics

gnuplot> set xtics ("left" -5, "middle" 0, "right" 5);gnuplot> set ytics ("max" 1, "zero" 0, "min" -0.2);gnuplot> plot [-10:10] [-1:2] sin(x)/x

用下面的办法可以查看一个数据文件中第二列和第三列的和的处理后数据。

gnuplot> plot "a.txt" using 1:($2+$3), "a.txt" using 1:2,"a.txt" using 1:3

可以用下面的办法,把绘图输出到 jpeg 格式的。

$echo "set terminal jpeg small ; plot sin(x)" | gnuplot  > a.jpg

可以 plot 用一些外部命令处理后的数据

gnuplot> plot "&lt; awk '{print $1,$2+$3,$2}' &lt; a.txt" using 1:2