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

GNUPLOT绘制2D热力图及指定区域切片的问题排查

解决Gnuplot热力图切片绘制的问题

首先,你遇到的every命令报错是因为语法格式错误——你在every ::13::17:后面多了一个不必要的冒号。Gnuplot的every命令语法是every [<point_incr>][:<block_incr>][:<start_point>][:<end_point>][:<start_block>][:<end_block>],末尾不需要额外的冒号。

方法1:修正every命令的语法

把切片绘图的代码改成这样就能正常运行了:

set output 'oups.png'
plot 'stack.dat' using 2:(log10($3)) every ::13::17 with lines notitle

这个命令会准确选取第13到17行的数据进行绘制。

方法2:更健壮的切片方法(推荐)

依赖行号的切片不够灵活——如果数据文件的行顺序发生变化,你的切片就会出错。更合理的方式是根据数据的实际列值进行过滤,比如你想绘制x=3(第一列等于3)的所有数据点(也就是热力图中x=3的竖切片),可以用where条件来筛选:

set output 'slice_x3.png'
plot 'stack.dat' using 2:(log10($3)) where $1 == 3 with lines notitle

如果想绘制y=2(第二列等于2)的横切片,就把条件改成$2 == 2:

set output 'slice_y2.png'
plot 'stack.dat' using 1:(log10($3)) where $2 == 2 with lines notitle

这种方法完全不依赖行号,无论数据怎么排序都能准确拿到你需要的切片。

完整的修正代码示例

这里给出包含热力图和切片绘制的完整可运行代码:

reset
set terminal pngcairo
set palette defined (0 "white", 1 "red")
unset key
set style fill solid

# 绘制完整热力图
set output 'stack.png'
plot 'stack.dat' using 1:2:(log10($3)) with boxes linecolor palette notitle

# 方法1:用修正后的every命令绘制第13-17行的切片
set output 'slice_by_row.png'
plot 'stack.dat' using 2:(log10($3)) every ::13::17 with lines notitle

# 方法2:用条件过滤绘制x=3的竖切片
set output 'slice_x3.png'
plot 'stack.dat' using 2:(log10($3)) where $1 == 3 with lines notitle

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:56:16