我知道这已经快 8 岁了,但我遇到了同样的问题,根据上面克里斯托夫的评论,我能够找到一种方法。
下面是我想要的图表:

然而,仅通过三元选择某些行并且与NaN
没有很好的配合smooth freq
,而且我的直方图是错误的(似乎箱是相互绘制的,并且频率没有达到应有的高)。
这不起作用:
plot \
'filename' using ($1 >= 0 ? $1 : NaN) notitle smooth freq with boxes fillcolor rgb "green", \
'filename' using ($1 < 0 ? $1 : NaN) notitle smooth freq with boxes fillcolor rgb "red"
在 gnuplot 5.4.2 的手册中,本节描述了一个实验功能,结合set table
,使我能够实现上图。
[实验] 要仅选择数据点的子集进行制表,您可以在命令末尾提供输入过滤条件 (if )。请注意,输入过滤器可能会引用不属于输出的数据列。在出现在 gnuplot 的已发布版本中之前,此功能可能会发生重大变化。
plot <file> using 1:2:($4+$5) with table if (strcol(3) eq "Red")
-- p207 gnuplot v5.4.2 手册
所以方法是:
- 用于
set table $my_data_block_green
设置下一个绘图命令输出到$my_data_block_green
数据块。我们将为每种颜色创建一个数据块,这是第一个。
- 用于
plot <file> with table if (<condition_for_green>)
仅将匹配的行写入绿色数据块<condition_for_green>
。
- 使用
set table $my_data_block_red
(如第 1 点)。
- 用于
plot <file> with table if (<condition_for_red>)
仅向红色数据块写入匹配的行<condition_for_red>
。
- 停止将绘图命令写入带有
unset table
.
- 正常绘图,引用数据块而不是
<file>
.
相关代码(不是上图的完整代码):
set table $db1
plot <filename> using 7:(1) with table if ($7 >= 0)
set table $db2
plot <filename> using 7:(1) with table if ($7 < 0)
unset table
plot \
'$db1' using $1:.. .. fillcolor rgb "green", \
'$db2' using $1:.. .. fillcolor rgb "red"
希望可以节省几分钟。