gnuplot - 为多维数据绘制缺少数据点的线
问题描述
我正在尝试从记录多个 GPU 数据的数据集中绘制多条表示 GPU 使用率随时间变化的线。每行包含时间戳、GPU 索引和使用百分比。
我的数据集如下所示:
$猫gpu.txt
#time #index # usage (%)
1,1,10
1,2,5
2,1,20
2,2,10
3,1,40
3,2,30
这是我的 gnuplot 脚本:
$猫情节.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
。如果您想要连接线,则必不可少的是线:set datafile missing 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
结果:
推荐阅读
- c# - 如何访问 DbMigration 中的 AppSetting?
- laravel - IDP Init SSO 流与 SimpleSAMLPhp + Laravel 应用程序(Saml2 包作为 SP)
- c# - 添加新控件时,是否有任何方法可以将面板上控件的 Z 顺序设置为始终位于顶部?
- javascript - 为什么装饰器会抛出无效类型的错误
- python - 如何一次在 numpy 数组列表中进行相同的计算?
- spring-boot - 为什么我在调用 camunda rest api 时收到 404 错误
- django - DRF - NestedSerializer 的 SerializerMethodField
- amazon-web-services - 如何创建 s3 存储桶子目录(无服务器)?
- javascript - 如何从 Okta 获取用户信息,而不是姓名、姓氏和电子邮件?
- python-3.x - 使用 python(使用 TLS 或 FTPS)为 Azure 应用程序安全部署 FTP