gnuplot 的使用

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 553813
2 661569 548566 556251 503663 461451 507295
3 723006 558036 518351 461444 429248 464006
4 748299 579828 510268 432925 403245 444233
5 770639 630340 558121 428781 409407 447517
6 773501 663703 580150 430565 414668 454168
7 773358 680100 602547 429561 415999 459455
8 772250 693620 616986 424956 416455 461635
9 767792 714011 642304 419132 413608 464747
10 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 1
gnuplot> set style line 1 linetype 2 linewidth 1 pointsize 2 pointtype 6
gnuplot> replot
gnuplot> set style line 1 linetype 2 linewidth 1 pointsize 2 pointtype 4
gnuplot> replot
gnuplot> set style line 1 linetype 2 linewidth 1 pointsize 2 pointtype 11
gnuplot> 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 2
gnuplot> replot
gnuplot> set border 2 linetype 3 # 左面的边框用 linetype 3
gnuplot> replot
gnuplot> set border 3 linetype 3 # 下面和左面的边框用 line type 3
border 后面的数字是一个12个bit 的整数,每一位bit 表示一个边框。 于是 1 ,2, 4, 8 分别对应下,左,上,右边框。

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

gnuplot> set grid
gnuplot> unset grid

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

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

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

gnuplot> set label 1 "Peak" at -5,0.8 right
gnuplot> set arrow 1 from -5,0.8 to -0.9,0.9 head
gnuplot> 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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值