自从 river 爱上了我强烈推荐的 LaTeX 后,我便变成了很多工具的小白。表格的题注和表格内容之间的距离需要调整,OK,我去查方法;他用illustrator/acrobat/gsview等等搞出来的 eps 图片不好用,使用 ps2eps 轻松搞定。一些小伎俩,非常有助于树立我的形象:)

这回,要根据一堆数据画出一些比较曲线。我立即想到了 gnuplot,虽然我之前也没有用过,但久仰大名。安装,运行,啊,是个命令行的东西?找到手册,学习几个小时,画图没有问题了:

画图的时候要使用到 plot 或者splot命令,前者画2D后者画3D。
gnuplot > plot sin(x)
画函数 sin(x)
gnuplot > plot ‘test.txt’ using 1:4 title ‘title a’ smooth csplines, \
‘’ using 1:5 title ‘title b’ smooth csplines
使用test.txt中的第一列和第四列画一条平滑的曲线,标记为 title a,
使用第一列和第五列画一条标记为title b的平滑曲线
gnuplot > f(x) = x
gnuplot > plot ‘test.txt’ using 4:5 with points pt 6, f(x)
比较第4列和第5列和函数f(x)=x的误差
gnuplot > set title “the title of the graph”
gnuplot > set xlabel “the label for x axis”
gnuplot > set ylabel “the label for y axis”
设置图片标识,X轴,Y轴标识。
控制gnuplot输出终端(格式)的是terminal属性。默认的terminal是x11,也就是画到屏幕上。
gnuplot > set terminal postscript eps
设置输出格式为 eps,得到的图片可以方便的插入 LaTeX 文档
gnuplot > set output "test.eps"
设置输出文件名。然后再 plot 就输出到 test.eps 里了。
gnuplot 支持的输出格式非常多,什么 latex, xfig, png等等。

同许多 *nix 下的工具一样,学习 gnuplot 需要花费一定的时间,但是一旦学会了你也许就受用终身。

ps, 为了画一条竖直的直线,在网上收到一个非常棒的教程:gnuplot tips(not so Frequently Asked Questions),配合gnuplot的手册,相信很快就能学会。

Technorati Tags: ,