GnuPlot:按第一个值的多个图 [英] GnuPlot: multiple graphs by first value
问题描述
我是GnuPlot的新手,感到有点困惑.我有这样的数据:
I'm new to GnuPlot and find it a bit confusing. I have data like this:
sensor1 timestamp temperature
sensor1 timestamp temperature
sensor1 timestamp temperature
sensor2 timestamp temperature
sensor2 timestamp temperature
sensor2 timestamp temperature
sensor3 timestamp temperature
sensor3 timestamp temperature
我仅对产生预期结果的一个传感器使用以下内容.
I use the following for only one sensor which produces the expected result.
使用2:($ 3/100.0):1并用线绘制'sensors.txt'
我想使用第一个值作为图形标题为每个传感器绘制图形.这听起来不像是一个复杂的问题,但是除了将每个传感器的数据分成一个文件外,我无法弄清楚.有更优雅的解决方案吗?
I want draw a graph for every sensor using the first value as the graph's title. It does not sound like a to complex problem but I could not figure it out other than splitting the data up into one file for each sensor. Is there a more elegant solution?
推荐答案
对此的一种解决方案是通过三元运算符按关键字进行过滤(请参见 help ternary
).
A solution to this is filtering by keyword via the ternary operator (see help ternary
).
您没有显示示例数据,所以我假设一些事情.
You don't show example data, so I assume something.
代码:
### split data by keyword for each plot
reset session
$Data <<EOD
sensor1 2020-06-21 12:00 24.3
sensor1 2020-06-21 13:00 25.3
sensor1 2020-06-21 14:00 22.3
sensor2 2020-06-21 15:00 23.3
sensor2 2020-06-21 16:00 22.3
sensor2 2020-06-21 17:00 21.3
sensor3 2020-06-21 18:00 25.3
sensor3 2020-06-21 19:00 23.3
sensor3 2020-06-21 20:00 27.3
EOD
myTimeFmt = "%Y-%m-%d %H-%M"
myFilter(fcol,key,dcol) = strcol(fcol) eq key ? column(dcol) : NaN
set datafile missing NaN
set format x "%Y\n%m-%d\n%H:%M" time
set xtics font ",8"
set ytics 1
set multiplot layout 3,1
do for [i=1:3] {
myKey = sprintf("sensor%d",i)
set title myKey
plot $Data u (timecolumn(2,myTimeFmt)):(myFilter(1,myKey,4)) w lp pt 7 lc i title myKey
}
unset multiplot
### end of code
结果:
这篇关于GnuPlot:按第一个值的多个图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!