Gnuplot 为多维数据打印缺少数据点的线

Gnuplot 为多维数据打印缺少数据点的线,gnuplot,Gnuplot,我试图从一个记录多个GPU数据的数据集中绘制多条线来表示GPU在一段时间内的使用情况。每行包含时间戳、GPU索引和使用率(以百分比为单位) 我的数据集如下所示: $cat gpu.txt #time #index # usage (%) 1,1,10 1,2,5 2,1,20 2,2,10 3,1,40 3,2,30 这是我的gnuplot脚本: $cat plot.gplot set datafile separator "," set autoscale #

我试图从一个记录多个GPU数据的数据集中绘制多条线来表示GPU在一段时间内的使用情况。每行包含时间戳、GPU索引和使用率(以百分比为单位)

我的数据集如下所示:

$cat gpu.txt

#time   #index   # usage (%)
1,1,10
1,2,5
2,1,20
2,2,10
3,1,40
3,2,30
这是我的gnuplot脚本:

$cat plot.gplot

set datafile separator ","
set   autoscale # scale axes automatically
unset log       # remove any log-scaling
unset label     # remove any previous labels
set xtic auto   # set xtics automatically
set ytic auto   # set ytics automatically
set title
set term png

set title "GPU usage"
set xlabel "Time"
set ylabel "Usage"

set output "gpu.png"

plot "gpu.txt" using ($2 == 1 ? $1 : NaN):($2 == 1 ? $3 : NaN) title 'GPU1' with linespoints ls 10 linecolor rgb "blue", \
     "gpu.txt" using ($2 == 2 ? $1 : NaN):($2 == 2 ? $3 : NaN) title 'GPU 2' with linespoints ls 10 linecolor rgb "red", \
不幸的是,这只绘制了单个数据点,而没有绘制线。我认为这是因为“缺少”数据点——显然不是这样,因为我有定制的过滤器,可以根据GPU索引绘制使用数据。我试图通过NaN值向gnuplot指出这一点,但它似乎不起作用

示例输出:


这是一个反复出现的过滤数据问题。 您可以定义线型,然后通过
ls i
在打印循环中使用它。 如果需要连接行,则必须使用以下行:
设置数据文件缺少NaN
。 我的最低建议是:

代码:

### filtering data
reset session

$Data <<EOD
#time   #index   # usage (%)
1,1,10
1,2,5
2,1,20
2,2,10
3,1,40
3,2,30
EOD

set datafile separator ","
set title "GPU usage"
set xlabel "Time"
set ylabel "Usage"

set key top left
set datafile missing NaN
myFilter(datacol,filtercol,value) = value==column(filtercol) ? column(datacol) : NaN

plot for [i=1:2] $Data u (myFilter(1,2,i)):3 w lp pt 7 title sprintf('GPU%d',i)
### end of code
过滤数据 重置会话 $Data