Chinaunix首页 | 论坛 | 博客
  • 博客访问: 71016
  • 博文数量: 26
  • 博客积分: 1070
  • 博客等级: 少尉
  • 技术积分: 285
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-27 09:32
文章分类

全部博文(26)

文章存档

2011年(1)

2010年(3)

2009年(22)

我的朋友

分类: LINUX

2009-10-14 11:02:07

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)
可以用下面的命令处理边框 。
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 "实战

般情况下使用gnuplot都是科学绘图,因此很多都是放在文章里面。一般优秀的科技文献都是用latex来编写的,所以gnuplot提供了直接输出
tex文件的功能,只需要把output设置为latex就可以了。下面来看一个例子,就把上面的正弦曲线插入到你的文章中。在命令行下输入:
gnuplot> set terminal latex
      set output "sin.tex"
      plot [-3.14:3.14] sin(x)
那么程序自动生成了一个tex文件,其包含一系列代码,都是绘图用的,可以用写字板打开,里面都是一些指令,你完全可以忽略掉。你可以把这个文件直接插入你的文章中,例如
\begin{figure}
   \begin{center}
\input{sin.tex}
   \end{center}
\end{figure}
如果你不需要图例,你可以在运行:
gnuplot> unset key
如果要还原
gnuplot> set key default
然后再运行上面的绘图命令就可以实现没有图例或者恢复图例的效果了
阅读(661) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~