到目前为止,我们所有的gnuplot作图都只是输出到电脑屏幕上。如果要在我们的文档里使用这些图片,我们必须把它们以某种文件格式存储下来。前面已经介绍过,gnuplot里面控制图像输出方式的命令是terminal。
输出到电脑屏幕:
gnuplot> set terminal wxt
输出为eps文件。
gnuplot> set terminal postscript eps所以首先选择eps,是因为大量科学技术文档使用 LaTeX 来编辑排版,而eps是 LaTeX 最常用的图片格式,支持高质量的矢量图形,并且可以方便的转换为pdf、svg等其他常用格式。
输入这个命令之后,gnuplot会自动返回下面的信息:
还是用我们上次用过的降水量数据文件:gnuplot> set xlabel "Month"gnuplot> set ylabel "Precipitation (mm)"gnuplot> set xrange [0.5:12.5]gnuplot> set xtics 1,1,12gnuplot> set output "precipitation.eps"gnuplot> plot "precipitation.dat" using 1:2 w lp pt 5 title "Beijing", "precipitation.dat" using 1:3 w lp pt 7 title "Shanghai"gnuplot> set outputgnuplot> set term wxt
第五行有一个新命令:set output。这没什么多说的,就是指定输出文件的文件名。第七行还有一个set output,但是后面没有跟任何文件名。这其实是告诉gnuplot,这个文件已经输出完毕,可以关闭了。另外也可以用unset output,其实是相同作用。之所以这么做,是因为有些terminal支持多页文件,所以在画完图之后,gnuplot并不自动关闭文件,等待你输入下一页内容,除非你手动关闭,切换terminal,或者退出gnuplot程序。