Gnuplot - 穿过整个绘图的恒定线

问题描述 投票:0回答:1

我有以下代码:

set autoscale xfix
set terminal qt size 1700, 650
stats "memory.log" prefix "A"
set key left top Left title "\n".sprintf('  Time:  %1.1f  h', A_records/1800.0)."\n".sprintf('   Max:  %d  GB', A_max) font ',11'
plot "memory.log" using (column(0)*2/3600):1 w lp notitle pt -1 lw 1

我想在整个图中添加一条线,该线仅在

A_max
超过常量值时绘制。我该怎么做呢?
If
条件很简单,但如何在整个图中绘制一个常数? (
memory.log
中没有针对此常数的单独数据列)。

linux plot gnuplot line
1个回答
0
投票

这是一个解决方案,但我仍在寻找一个更简单的解决方案......

创建一些随机测试数据,在示例中,如果最大 y 值 >9,则用值

myConstant
绘制水平线。运行脚本几次,您会看到是否绘制了水平线。

在示例中,值

ymax
是在绘制数据期间提取的,但您也可以通过
ymax
提取
stats
,就像您在示例中所做的那样。

脚本:

### plot conditional horizontal line
reset session

# create some random data
set table $Data
    set samples 11
    plot '+' u 0:(int(rand(0)*11)) w table
unset table

set key noautotitle
set yrange[0:10]
myMax      = 9
myConstant = 5

plot ymax=NaN $Data u 1:($2<ymax ? $2 : ymax=$2) w lp pt 7 lc "red", \
     '+' u 1:(ymax>myMax ? myConstant :  NaN) w l lc "blue"
### end of script

结果:

ymax=8,未绘制线。

ymax=10,绘制线

© www.soinside.com 2019 - 2024. All rights reserved.