我们现在所有绘图的坐标刻度均标在图像边框上,无论上下左右。这样做的好处是函数或数据图线清楚,不会和坐标标注混在一起。其实,我们小时候数学课上最早学习坐标系的时候,都是让 X 轴和 Y 轴正交于原点,而刻度标注在坐标轴上。这样的图像在定性表现函数关系,尤其有一定对称性的函数关系时,比较一目了然。
让我们来看看怎样用 gnuplot 得到这样的效果。
用 unset border 命令把边框去掉;
用 set zeroaxis 命令画出正交于原点的坐标轴;
在设定坐标刻度时加上 axis 参数,这样刻度会出现在坐标轴上面,而不是边框上。
为了避免审美疲劳,这次我们拿高斯函数举个例子:
gnuplot> set term wxt enhanced font "Times New Roman,16" gnuplot> gauss(x) = exp(-pi*x*x) gnuplot> set title "函数 e^{-πx^2}" gnuplot> set samples 500 gnuplot> set xrange [-3:3] gnuplot> set yrange [-0.2:1.2] gnuplot> unset key gnuplot> unset border gnuplot> set zeroaxis lt -1 lw 2 gnuplot> set xtics axis -2,1,2 gnuplot> set ytics axis 0,1,1 gnuplot> plot gauss(x) lw 3
gnuplot> set title "函数 e^{-πx^2}" offset 12,-5 gnuplot> set xtics axis -2,1,2 offset 0.4,0 gnuplot> set ytics axis 0,1,1 offset 0,0.4 gnuplot> set arrow 1 from 2,0 to 3.2,0 filled size 0.2,15,60 lw 2 gnuplot> set arrow 2 from 0,1 to 0,1.22 filled size 0.2,15,60 lw 2 gnuplot> set rmargin 4 gnuplot> set label 1 "X" at 3.0,-0.1 gnuplot> set label 2 "Y" at -0.3,1.2 gnuplot> replot