绘制缺少多维数据的数据点的线 [英] Plotting lines with missing datapoints for multidimensional data
问题描述
我正在尝试从记录多个GPU数据的数据集中绘制表示随时间推移GPU使用情况的多条线.每行包含时间戳记,GPU索引和使用率(百分比).
I'm trying to plot multiple lines representing GPU usage over time from a dataset which records data of multiple GPUs. Each row contains the timestamp, a GPU index and the usage in percent.
我的数据集如下:
$ cat gpu.txt
$ 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脚本:
and this is my gnuplot script:
$ cat plot.gplot
$ 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,但它似乎不起作用.
Unfortunately, this only ever draws the singular datapoints, but no lines. I think this is because of "missing" datapoints - which is not the case obviously because I have the custom filters in place to plot usage data per GPU index. I tried to indicate this to gnuplot via the NaN value, but it doesn't seem to work.
示例输出:
推荐答案
这是一种重复出现的过滤数据问题.您可以定义线型,然后通过 ls i
在绘图循环中使用它.如果要连接线,则必不可少的是: set datafile missing NaN
.我的最小建议是:
This is kind of a recurring filtering data question.
You can define linestyles and then use it in the plotting loop via ls i
.
Essential if you want connecting lines is the line: set datafile missing NaN
.
My minimal suggestion would be:
代码:
### 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
结果:
这篇关于绘制缺少多维数据的数据点的线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!