从多天绘制相同的TimePeriod

时间:2015-09-16 14:08:47

标签: gnuplot

我的数据看起来像这样: FILE_A

2015-08-01 00:00    424.9563018750976
2015-08-01 00:01    785.7380434263472
....
2015-08-01 23:59

File_B

2015-08-02 00:01    1.4625096463725384
2015-08-02 00:02    6.0047607076482485
....
2015-08-02 23:59

因此日期格式为:%Y-%m-%d%H:%M 我想绘制整个月的系列节目,但是对于每一天只有一个时间段,例如09:00 - 15:00。

这是我试过的:

clear
reset
cd 'C:\Users\SammerP\Desktop\Desktop Calc\AIT ALL\CatchAllDataAIT\data'
set title 'Data of Month' font 'bold verdana,08'
set xdata time
set timefmt '%Y-%m-%d %H:%M'
set format x '%Y-%m-%d %H:%M'
set ylabel 'Value' 
set yrange [550:700]
set ytics (550,560,570,580,590,600,610,620,630,640,650,660,670,680,690,700,710,720,730,740,750,760,770,780,790,800)
set xtics rotate by 45 offset -1.5,-1.2
set xrange ['2014-08-01 09:00':'2014-08-31 15:00']

set xtics ('08-01' '2014-08-01 13:00','08-02' '2014-08-02 13:00','08-03' '2014-08-03 13:00','08-04' '2014-08-04 13:00','08-05' '2014-08-05 13:00',\
'08-06' '2014-08-06 13:00','08-07' '2014-08-07 13:00','08-08' '2014-08-08 13:00','08-09' '2014-08-09 13:00','08-10' '2014-08-10 13:00','08-11' '2014-08-11  13:00',\
'08-12' '2014-08-12 13:00','08-13' '2014-08-13 13:00','08-14' '2014-08-14 13:00','08-15' '2014-08-15 13:00','08-16' '2014-08-16 13:00',\
'08-17' '2014-08-17 13:00','08-18' '2014-08-18 13:00','08-19' '2014-08-19 13:00','08-20' '2014-08-20 13:00','08-21' '2014-08-21 13:00',\
'08-22' '2014-08-22 13:00','08-23' '2014-08-23 13:00','08-24' '2014-08-24 13:00','08-25' '2014-08-25 13:00','08-26' '2014-08-26 13:00',\
'08-27' '2014-08-27 13:00','08-28' '2014-08-28 13:00','08-29' '2014-08-29 13:00','08-30' '2014-08-30 13:00','08-31' '2014-08-31 13:00')
set grid
set nokey
plot'File_A.csv' using 1:2 axes x1y1 linewidth 1 lc rgb 'red' w l,\
'File_B' using 1:2 axes x1y1 linewidth 1 lc rgb 'red' w l,
..........

我通过仅绘制每个文件中的特定行来尝试它,但是我最终在这些日子之间插入了一个洞。 我想也许问题是xrange设置所以我删除了,但问题是相同的

有没有办法设置xrange,以便Gnuplot从第1天到第31天,每天从09:00从15:00开始,并且在这些日子之间没有空格。

以下是现在的样子:

enter image description here

1 个答案:

答案 0 :(得分:2)

使用gnuplot无法自动完成。在我看来,你最好的选择是不使用时间轴,而是使用正常的数字轴,并提供自己的映射来正确标记xtics,并调整你想要的日期之间的差距。

这是一个可能的解决方案,但如果没有适当的测试数据,我无法验证我是否已完成所有步骤:

gapBetweenDaysInSeconds = 1000
startHour = 9.0
endHour = 15.0

set xtics ("01-08" (13-startHour)*60*60)
set for [i=2:31] xtics add (sprintf("08-%02d", i) ((i-1)*(endHour-startHour) + 13 - startHour)*60*60 + (i-1)*gapBetweenDaysInSeconds)

# for gnuplot 5.0
# gettime(col) = timecolumn(col, '%Y-%m-%d %H:%M')
# for all gnuplot version.
gettime(col) = strptime('%Y-%m-%d %H:%M', strcol(col).' '.strcol(col+1))

files="File_A.csv File_B.csv File_C.csv" # ... to be continued

plot for [file in files] file using (t=gettime(1), tm_hour(t) < startHour || tm_hour(t) >= endHour ? 1/0 : (((tm_mday(t)-1)*(endHour-startHour) + (tm_hour(t)-startHour))*60 + tm_min(t))*60 + tm_sec(t) + (tm_mday(t)-1)*gapBetweenDaysInSeconds):2 lt 1

假设您每天有一个文件,并且这些文件在变量files中以空格分隔。

set xtics的第一次调用只设置一个xtic并删除所有其他xtic。然后我使用set xtics add在循环中添加所有后续抽搐。

对于每一行,使用gettime用户定义的函数解析时间戳,并将其分配给变量t。在第二步中,我使用tm_*函数仅提取mont,hour,minutes和seconds的日期,并计算自相应月份的第一天以来以秒为单位给出的x轴上的位置。可以使用变量gapBetweenDaysInSeconds给出两天之间的差距。

当月被硬编码为08

这应该是一个合理的起点。