GnuPlot: multiple graphs by first value

血红的双手。 提交于 2020-12-15 05:27:05

问题


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.

plot 'sensors.txt' using 2:($3/100.0):1 with lines

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?


回答1:


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.

Code:

### 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

Result:



来源:https://stackoverflow.com/questions/62484678/gnuplot-multiple-graphs-by-first-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!