You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gnuplot:splot绘制彩色图叠加2D采样点异常问题求助

Gnuplot绘制彩色图并叠加空间采样点的问题

需求

使用Gnuplot的splot命令绘制彩色图(colourmap),同时叠加空间采样点,以下是3维场景的示例代码及遇到的问题。

设置命令

number_of_variables = 3
set contour base
set palette model RGB
set palette defined ( 0 'white', 1 'dark-red' )
set dgrid3d 31, 31
unset clabel
unset surface
set view map
set pm3d 
set datafile missing NaN

绘图代码段

do for [i=1:number_of_variables-1]{ 
  set xlabel sprintf("b %d", i)
  do for [j=i+1:number_of_variables] {
    set ylabel sprintf("b %d", j)
    set title sprintf("Kriging预期改进值:采样点 %d vs %d", i, j)
    splot "sf1.dat" using i:j:(((column(number_of_variables+1) == (i-1))||(column(number_of_variables+1) == -1)&&((column(number_of_variables+2) == (j-1))||(column(number_of_variables+2) == -1))) ? column(number_of_variables+5) : 1/0) notitle w l lt -1, \
            "sf2.dat" using i:j:(0) w p pt 7 ps 1.5 lc rgb "black" title "采样点"
    pause -1 
  }
}

数据说明

  • sf1.dat共6列,包含3维坐标、规则列与彩色图数值列,共31^3行;
  • sf2.dat共3列,为采样点的3维坐标,约35行。

问题描述

执行splot命令时,预期的黑色采样点未显示,反而出现白色矩形(因设置z值为0)。若改用2D表格方式绘图,采样点位置正确,但只能显示等高线而非彩色图。使用的Gnuplot版本为5.4 patchlevel 2,求解决叠加问题的方法。


解决方法

核心问题

  1. 原代码第一部分splot用w l绘制等高线,而非pm3d样式,未生成彩色图;
  2. 采样点z值设为0,在view map模式下被pm3d图层遮挡;
  3. 图层顺序未调整,导致采样点被覆盖。

修正代码

number_of_variables = 3
set contour base
set palette model RGB
set palette defined ( 0 'white', 1 'dark-red' )
set dgrid3d 31, 31
unset clabel
unset surface
set view map
set pm3d depthorder  # 开启pm3d图层深度排序
set datafile missing NaN

do for [i=1:number_of_variables-1]{ 
  set xlabel sprintf("b %d", i)
  do for [j=i+1:number_of_variables] {
    set ylabel sprintf("b %d", j)
    set title sprintf("Kriging预期改进值:采样点 %d vs %d", i, j)
    # 先绘制pm3d彩色图
    splot "sf1.dat" using i:j:(((column(number_of_variables+1) == (i-1))||(column(number_of_variables+1) == -1)&&((column(number_of_variables+2) == (j-1))||(column(number_of_variables+2) == -1))) ? column(number_of_variables+5) : 1/0) notitle with pm3d, \
            # 采样点设为彩色图最大值范围(假设0-1),强制显示在顶层
            "sf2.dat" using i:j:(1) w p pt 7 ps 1.5 lc rgb "black" title "采样点" front
    pause -1 
  }
}

关键调整说明

  • set pm3d depthorder:让pm3d根据z值自动排序图层,避免遮挡;
  • 第一部分绘图改为with pm3d:真正生成彩色图,保留等高线可额外添加with lines语句;
  • 采样点z值设为1(匹配彩色图0-1范围),加front选项:强制采样点显示在所有图层上方;
  • 若彩色图数值范围不同,可将采样点z值设为数据实际最大值,或一个大于所有彩色图z值的固定数。

内容的提问来源于stack exchange,提问作者Edo07

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 08:23:11