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

gnuplot hidden3d:如何自定义曲面上下视图的颜色?

Gnuplot hidden3d 曲面颜色问题解决

一、顶/底面颜色差异原因

  • Gnuplot的hidden3d默认根据曲面法向量朝向自动分配颜色:朝向观察者的面使用当前调色板前半段颜色,背向面使用后半段。
  • 你遇到的顶绿底蓝与示例顶蓝底绿的差异,核心是曲面法向量方向相反,通常由数据矩阵的行/列遍历顺序(如y轴递增/递减)或视角设置不同导致。

二、自定义顶蓝底灰的解决方案

要实现顶部蓝色、底部浅灰色,需利用hidden3d的前后颜色控制特性,而非全局linecolor设置。

修改后的控制命令

替换原有splot相关配置,关键是在set hidden3d中指定前后颜色:

fprintf (gnuplotPipe, "set terminal windows\n");
fprintf (gnuplotPipe, "set hidden3d front lc 'blue' back lc 'light-gray'\n");  // 核心配置:区分前后颜色
fprintf (gnuplotPipe, "set title '3D Surface'\n");
fprintf (gnuplotPipe, "set zrange [0:100]\n");
fprintf (gnuplotPipe, "set xyplane  at 0\n");
fprintf (gnuplotPipe, "unset key\n");
fprintf (gnuplotPipe, "splot '-' nonuniform matrix using 1:2:3 with lines\n");
fprintf (gnuplotPipe, "\n");

原理说明

  • set hidden3d front lc 'blue' back lc 'light-gray':直接为朝向观察者的面(顶部)设置蓝色,背向面(底部)设置浅灰色,这是Gnuplot为hidden3d专门设计的前后颜色控制参数,逻辑贴合3D视觉需求。
  • 若使用旧版Gnuplot(<5.0)不支持front/back参数,可改用调色板映射方案:
    fprintf (gnuplotPipe, "set palette defined (0 'light-gray', 1 'blue')\n");
    fprintf (gnuplotPipe, "set hidden3d\n");
    fprintf (gnuplotPipe, "splot '-' nonuniform matrix using 1:2:3:(sign($3 - 50)) with lines linecolor palette\n");
    
    这里以z轴中间值50为分界,通过sign($3 - 50)生成-1/1的标识,映射到自定义调色板的两种颜色,间接区分上下表面。

注意事项

  • 建议使用Gnuplot 5.0及以上版本,front/back参数已稳定支持。
  • 视角旋转时,颜色会随曲面法向量朝向自动调整,保持视觉一致性。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 06:18:11