虽然www.gnuplot.info 上有很多关于轮廓的例子,但我找不到你的确切情况,因为这些例子是函数,而不是数据块或数据文件(嗯,应该是相似的)。
以下代码可以满足您的要求,但是用于添加标签的构造 '' u 1:2:3:("") w labels 对我来说仍然看起来很奇怪,并且不允许绘制盒装标签。
在 gnuplot 控制台中检查 help contour 和 help cntrparam。
代码:
### pm3d with contour lines
reset session
set view equal xyz
# create some test data
set samples 40
set isosamples 40
set table $Data
splot '++' u 1:2:($1*$2/2-9)
unset table
set view map
set contour base
set cntrparam levels incremental -20,2,-8
set cntrlabel font ",10"
set xrange[-5:5]
set yrange[-5:5]
splot $Data u 1:2:3 w pm3d notitle, '' u 1:2:3:("") w labels notitle
### end of code
结果:
加法:
这是使用plot w image 而不是splot w pm3d 的另一种方法。
尽管轮廓线顶部的白色标签框仍然不能完全令人满意。向标签添加偏移量不会同时适用于所有标签。我不确定是否有办法只打断标签的轮廓线。
代码:
### heatmap with contour lines
reset session
set view equal xyz
# create some test data
set samples 40
set isosamples 40
set table $Data
splot '++' u 1:2:($1*$2/2-9)
unset table
set view map
set contour base
set cntrparam levels incremental -20,2,-8
set cntrlabel font ",10"
set xrange[-5:5]
set yrange[-5:5]
set style textbox noborder opaque
# put contour lines in a separate datablock
unset surface
set table $Contour
splot $Data u 1:2:3
unset table
plot $Data u 1:2:3 w image notitle, \
$Contour u 1:2 w l lw 2 lc "black" not, \
'' u 1:2:3 every 40::3 w labels boxed notitle
### end of code
结果:
加法2:
另一种用彩色轮廓线和键代替标签的变体。这个好像有点麻烦,希望有更简单的解决方法。
代码:
### heatmap with colored contour lines
reset session
set view equal xyz
# create some test data
set samples 40
set isosamples 40
set table $Data
splot '++' u 1:2:($1*$2/2-9)
unset table
set view map
set contour base
set cntrparam levels incremental -20,2,-8
set xrange[-5:5]
set yrange[-5:5]
set style textbox noborder
# put contour lines in a separate datablock
unset surface
set table $Contour
splot $Data u 1:2:3
unset table
# get contour levels unique and in sorted order
set table $Dummy
plot $Contour u 3 w table
unset table
set table $ContourSorted
plot $Dummy u 1 smooth freq
unset table
print $ContourSorted
set key out right Left
plot $Data u 1:2:3 w image notitle, \
for [i=0:*] $Contour u 1:2:3 index i w l lw 2 lc i+1 not, \
for [i=|$ContourSorted|-2:5:-1] $ContourSorted u (NaN):1 w l lw 2 lc |$ContourSorted|-i-1 ti word($ContourSorted[i],1)
### end of code
结果: