如何将轮廓线添加到热图 [英] How to add contour lines to a heat map

查看:65
本文介绍了如何将轮廓线添加到热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本来获取数据(格式为3列 x,y,z )并提供热图:

 设置对数刻度x 10设置yrange [1e-9:2e-8]将xlabel设置为"x"将ylabel设置为y设置多图用图像绘制'filetest.dat'u 1:2:9 

这是2D热图,如下所示:

我要做的就是以2个间隔的z值(例如-20到-8)将轮廓添加到此绘图中,不幸的是,我发现的所有答案都无法帮助我解决这个问题.任何帮助将不胜感激.

解决方案

尽管

添加:

这里是使用 plot w image 代替 plot w pm3d 的另一种方法.尽管轮廓线顶部的白色标签框仍不完全令人满意.向标签添加偏移量将无法同时适用于所有标签.我不确定是否有办法只中断标签的轮廓线.

代码:

  ###带轮廓线的热图重置会话设置视图等于xyz#创建一些测试数据设置样本40设置等值样本40设置表$ Data散点'++'u 1:2:($ 1 * $ 2/2-9)未设置表格设置视图图设定轮廓基准设置cntrparam级别增量-20,2,-8将cntrlabel字体设置为,10"设置xrange [-5:5]设置yrange [-5:5]设置样式文本框noborder不透明#将轮廓线放在单独的数据块中未固化的表面摆放桌子$ Contour散点图$ Data u 1:2:3未设置表格绘制$ Data u 1:2:3 w图片无标题,\$轮廓u 1:2 w l lw 2 lc黑色"不是, \''每40 :: 3的u 1:2:3 w标签盒装无标题###代码结尾 

结果:

添加2:

另一种变体,带有彩色轮廓线和关键点而不是标签.这似乎有点麻烦,我希望有一个更简单的解决方案.

代码:

  ###带有彩色轮廓线的热图重置会话设置视图等于xyz#创建一些测试数据设置样本40设置等值样本40设置表$ Data散点'++'u 1:2:($ 1 * $ 2/2-9)未设置表格设置视图图设定轮廓基准设置cntrparam级别增量-20,2,-8设置xrange [-5:5]设置yrange [-5:5]设置样式文本框noborder#将轮廓线放在单独的数据块中未固化的表面摆放桌子$ Contour散点图$ Data u 1:2:3未设置表格#获得轮廓级别唯一且按顺序排列的轮廓摆放桌子$ Dummy绘制$ Contour u 3 w表未设置表格摆放桌子$ ContourSorted绘制$ Dummy u 1平滑频率未设置表格打印$ ContourSorted将键设置为右向左绘制$ Data u 1:2:3 w图片无标题,\对于[i = 0:*] $ Contour u 1:2:3 index i w l lw 2 lc i + 1 not,\对于[i = | $ ContourSorted | -2:5:-1] $ ContourSorted u(NaN):1 w l lw 2 lc | $ ContourSorted | -i-1 ti word($ ContourSorted [i],1)###代码结尾 

结果:

I have a script which takes data (formatted in 3 columns x,y,z) and gives a heat map:

set logscale x 10
set yrange [1e-9:2e-8]

set xlabel "x"
set ylabel "y"
set multiplot


plot 'filetest.dat' u 1:2:9 with image

This is a 2D heat map, shown below:

All I want to do is add contours to this plot, at some z values such as -20 to -8 in in intervals of 2. Unfortunately, none of the answers I've found have been able to help me with this. Any help would be greatly appreciated.

解决方案

Although there are a lot of examples about contour on www.gnuplot.info, I couldn't find your exact case, because the examples are with functions, not with datablocks or data files (well, it should be similar). The following code does what you're asking for, but the construct '' u 1:2:3:("") w labels for adding labels still looks strange to me and doesn't allow for plotting boxed labels. In gnuplot console check help contour and help cntrparam.

Code:

### 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

Result:

Addition:

Here is another approach with plot w image instead of splot w pm3d. Although still not fully satisfying with the white label boxes on top of the contour lines. Adding an offset to the labels will not work for all labels at the same time. I'm not sure whether there is a way to just interrupt the contour lines for the labels.

Code:

### 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

Result:

Addition 2:

Another variation with colored contour lines and key instead of labels. This seems to be a bit cumbersome, I hope there is a simpler solution for this.

Code:

### 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

Result:

这篇关于如何将轮廓线添加到热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆