你没有展示你的确切数据结构是什么样子的,所以我假设了一些东西。为了说明一些事情,我创建了一些测试数据,这些数据在第一列中有时间戳,在第二列中有一些值。此外,我假设您的数据在每一天开始之前都没有空行,这将使生活更轻松。无论如何,您仍然可以使用 gnuplot 完成这一切,而无需外部脚本。
首先,您必须设置开始日期,例如"29.08.2019 00:00:00"。通过使用模 %86400(每天 86400 秒),您将每 24 小时绘制一次。使用对虚拟数据块$Dummy 的单独绘图命令,您将提取每天的最大值并将最大值放入数组DailyMax。然后创建一个显示这些值的标签。最后,绘制所有曲线。如果您需要对某些细节进行更多解释,请随时询问。
我希望,我正确理解了您的问题,并且您可以根据自己的需要调整建议。使用 gnuplot 5.2.6 测试。
代码:
### timestamp plot for 24h with extraction of daily maximum
reset session
set colorsequence classic
# define some values and functions
StartTime = strptime("%d.%m.%Y %H:%M:%S", "29.08.2019 00:00:00")
NoOfDays = 5
Hours24(n) = int(n-StartTime)%86400
DayNo(n) = int((n-StartTime)/86400)
# generate some dummy data
set print $Data
t(n) = StartTime + n*5*60
do for [i=0:NoOfDays-1] {
A = rand(0)*70+30
p(n) = A*exp(-(n%288-144-rand(0)*10)**2/(720+rand(0)*2000))
do for [j=0:287] {
print sprintf("%.0f\t%f",t(i*288+j),p(i*288+j))
}
}
set print
# extract the maximum of each day and store it in an array
array DailyMax[NoOfDays]
DayPrev = NaN
set table $Dummy
plot $Data u (DayPrev!=DayNo($1) ? Comp=$2 : 0, DayPrev=DayNo($1), \
$2>=Comp ? (Comp=$2, DailyMax[DayNo($1)+1]=Comp) : 0) with table
unset table
print DailyMax
# create label with max values
do for [i=1:NoOfDays] {
set label i at graph 0.05, 0.95-i*0.05 tc lt i-1 sprintf("Max of day %d: %.1f\n", i, DailyMax[i])
}
set xdata time
set format x "%H:%M"
set timefmt "%s"
plot $Data u (Hours24($1)):2:(DayNo($1)) w l lc var notitle
### end of code
结果:
加法:
假设我现在已经理解了你,那么你可以简单地绘制你的数据with boxes。无需提取最大值。较高的方框将覆盖较短的方框。
代码:
### timestamp plot plot maximum within every 5 min interval over all days
reset session
set colorsequence classic
# define some values and functions
StartTime = strptime("%d.%m.%Y %H:%M:%S", "29.08.2019 00:00:00")
NoOfDays = 5
Hours24(n) = int(n-StartTime)%86400
DayNo(n) = int((n-StartTime)/86400)
# generate some dummy data
set print $Data
t(n) = StartTime + n*5*60
do for [i=0:NoOfDays-1] {
A = rand(0)*70+30
p(n) = A*exp(-(n%288-144-rand(0)*10)**2/(720+rand(0)*2000))
do for [j=0:287] {
print sprintf("%.0f\t%f",t(i*288+j),p(i*288+j))
}
}
set print
set xdata time
set format x "%H:%M"
set timefmt "%s"
plot $Data u (Hours24($1)):2 w boxes fill solid 1.0 fc "web-green" notitle
### end of code
结果:
加法2:
现在,我想我们越来越近了。我修改了代码。您可以输入要绘制的数据的时间范围。您需要从数据顶部跳过 7 行,因为它们不以注释字符开头,例如#。检查下面的代码。
它的代码要简单得多,但是让我感到困惑的是,您不能在 plot 命令中直接使用函数Hours24(n)。它将在 00:00 为您提供一个高峰。我还不明白为什么。
交换最后两行就可以测试了
set xrange[0:86400]
plot $Data u 1:2 w boxes fill solid 1.0 fc "web-blue" notitle
与
set xrange[-10000:86400]
plot FILE u (Hours24($1)):4 skip 7 w boxes fill solid 1.0 fc "web-blue" notitle
代码:(针对自动完整时间范围进行了编辑)
### timestamp plot; put values of days on top of each other
reset session
FILE = 'log-pv-20190607-20190811.csv'
# automatic StartTime, EndTime
# StartTime always has to start at 00:00:00
stats FILE u 1 skip 7 nooutput
StartTime = strptime("%d.%m.%Y", strftime("%d.%m.%Y", STATS_min) )
EndTime = STATS_max
# alternatively, manually set StartTime, EndTime
# StartTime = strptime("%d.%m.%Y", "08.08.2019")
# EndTime = strptime("%d.%m.%Y %H:%M:%S", "11.08.2019 23:59:59")
print "StartTime: ", strftime("%d.%m.%Y %H:%M:%S", StartTime)
print "EndTime: ", strftime("%d.%m.%Y %H:%M:%S", EndTime)
Hours24(n) = (n<StartTime || n>EndTime) ? "" : (int((n-StartTime))%86400)
# This extra of plotting to $Data step seems to be necessary,
# because if you plot directly via
# plot FILE u (Hours24($1)):4 skip 7 w boxes fill solid 1.0 fc "web-blue" notitle
# you will get some value at 00:00, which I don't understand. A bug?
set table $Data
plot FILE u (Hours24($1)):4 skip 7 w table
unset table
set xdata time
set format x "%H:%M"
set timefmt "%s"
set yrange[0:]
set xrange[0:86400]
plot $Data u 1:2 skip 7 w boxes fill solid 1.0 fc "web-blue" notitle
### end of code
结果:(现在有您的数据)