等高线图是另一类重要的 3D 绘图方式。为了说明 gnuplot 里面等高线图的绘制方法,我们使用下面这个数据文件作为例子:
surface.dat
首先绘制普通曲面图:
gnuplot> set hidden3d
gnuplot> splot "surface.dat" with lines
下面加上等高线:
gnuplot> set contour base
gnuplot> splot "surface.dat" with lines title ""
set contour 命令之后除了
base 参数外,还可以使用
surface 或
both 参数,分别表示等高线画在底面、曲面或者两者都画。这里设置了一个空的
title,是为了在图例中不要显示文件名,以免和等高线的图例混淆。
如果我们想在平面中显示等高线,可以使用下列命令:
gnuplot> unset surface
gnuplot> set view map
gnuplot> set size square
gnuplot> replot
如果我们想在之前提到过的 pm3d 图上显示等高线,可以这样做:
gnuplot> set pm3d at b
gnuplot> set key at screen 0.8,0.8
gnuplot> replot
这里我们把图例的位置做了调整,因为默认图例是在图像里面的,这样可能影响我们的图像显示。
最后,我们谈谈怎样手动设置等高线数值和间距。等高线的数值间隔参数设置命令是
set cntrparam levels。默认情况下,gnuplot 自动设置等高线数值。如果要进行手动设置,有两种方法:
- incremental <start>,<incr>,<end>
设置起始值以及间隔大小,这种方法适用于等间隔的等高线; - discrete <z1>,<z2>,<z3>,…
分别设置各个等高线数值,这种方法适用于间隔不等的等高线。
例子:
gnuplot> set cntrparam levels incremental -2,0.5,2
gnuplot> replot
https://m.sciencenet.cn/blog-373392-520793.html
上一篇:
谈谈gnuplot(三十):image 绘图下一篇:
谈谈gnuplot(三十二):等高线的颜色