Gnuplot——向 x 轴添加过多数据
Gnuplot-- adding too much data to xaxis
我有一个文件是 "date,time,temperature" 换行 "date,time,temperature" etc
示例:
12/01/19,23:30:13,74.23
12/01/19,23:45:13,74.33
12/02/19,00:00:13,74.20
12/02/19,00:15:13,74.06
我希望使用 Gnuplot 对其进行绘图。
绘图部分效果很好,而且在大多数情况下,它看起来可以满足我的需要。
但是,xtics 正在添加额外的信息,我没有为他们设置这些信息,也不知道这些信息来自哪里。
代码:
set terminal gif animate delay 200
set output "path/to/file.gif"
set datafile separator ","
set title 'Temperature in Aquarium"
set key bottom left box
set key width 1
stats "path/to/file.csv" using 2:3 name "A"
set xlabel 'Time'
set xdata time
set timefmt '%H:%M'
set xtics 14400
set ylabel 'Temp(F)'
set yrange [68:80]
set style data lines
do for [i=0:int(A_blocks-1)] { plot 'path/to/file.csv' using 2:3 index i title "Dec " .(i+1)
我希望在 x 轴上看到的只是“00:00、04:00、08:00、12:00、16:00、 20:00, 00:00"
对于从今天收集的任何数据,我确实看到了这一点。
但是从前一天收集的任何数据看起来像:
"01/01 00:00, 01/01/ 04:00, 01/01 08:00, 01/01 12:00"...
之后的每一天都对 x 轴重复该操作,直到获得今天的数据,然后显示“00:00、04:00、08:00... "
我怎样才能让它不显示前几天的“01/01”?
完全修改代码。
我猜你还没有设置 x 轴的格式,例如set format x "%H:%M"
。
我认为 set xdata time
有点 "outdated",而不是使用 set format x "%H:%M" timedate
,正如您可能知道的那样,时间从 01/01/1970 开始按秒处理。
这里是进一步调整的可能起点。
代码:
### animated time data
reset session
set term gif size 480,320 animate delay 100
set output "Animation.gif"
set datafile separator ","
myTimeFmt = '%m/%d/%y,%H:%M:%S'
# generate some test data
StartDateTime = strptime(myTimeFmt, "12/18/19,00:00:00")
set print $Data
do for [day=0:7] {
do for [i=0:24*4-1] {
print strftime(myTimeFmt,StartDateTime+day*24*3600 + i*15*60). \
",".sprintf("%.1f",74+6*sin(i/12.)+rand(0)*3)
}
if (day<7) { print ""; print ""} # 2 empty lines at the end of the day
}
set print
set timefmt myTimeFmt
set format x "%H:%M" timedate
set xtics 4*3600
stats $Data u 0 nooutput
set key top center
do for [i=0:STATS_blocks-1] {
plot $Data u (timecolumn(1,myTimeFmt)):3 index i w lp pt 7 ti strftime("%b %d", StartDateTime+i*24*3600)
}
set output
### end of code
结果:
我有一个文件是 "date,time,temperature" 换行 "date,time,temperature" etc
示例:
12/01/19,23:30:13,74.23
12/01/19,23:45:13,74.33
12/02/19,00:00:13,74.20
12/02/19,00:15:13,74.06
我希望使用 Gnuplot 对其进行绘图。
绘图部分效果很好,而且在大多数情况下,它看起来可以满足我的需要。
但是,xtics 正在添加额外的信息,我没有为他们设置这些信息,也不知道这些信息来自哪里。
代码:
set terminal gif animate delay 200
set output "path/to/file.gif"
set datafile separator ","
set title 'Temperature in Aquarium"
set key bottom left box
set key width 1
stats "path/to/file.csv" using 2:3 name "A"
set xlabel 'Time'
set xdata time
set timefmt '%H:%M'
set xtics 14400
set ylabel 'Temp(F)'
set yrange [68:80]
set style data lines
do for [i=0:int(A_blocks-1)] { plot 'path/to/file.csv' using 2:3 index i title "Dec " .(i+1)
我希望在 x 轴上看到的只是“00:00、04:00、08:00、12:00、16:00、 20:00, 00:00"
对于从今天收集的任何数据,我确实看到了这一点。 但是从前一天收集的任何数据看起来像:
"01/01 00:00, 01/01/ 04:00, 01/01 08:00, 01/01 12:00"...
之后的每一天都对 x 轴重复该操作,直到获得今天的数据,然后显示“00:00、04:00、08:00... "
我怎样才能让它不显示前几天的“01/01”?
完全修改代码。
我猜你还没有设置 x 轴的格式,例如set format x "%H:%M"
。
我认为 set xdata time
有点 "outdated",而不是使用 set format x "%H:%M" timedate
,正如您可能知道的那样,时间从 01/01/1970 开始按秒处理。
这里是进一步调整的可能起点。
代码:
### animated time data
reset session
set term gif size 480,320 animate delay 100
set output "Animation.gif"
set datafile separator ","
myTimeFmt = '%m/%d/%y,%H:%M:%S'
# generate some test data
StartDateTime = strptime(myTimeFmt, "12/18/19,00:00:00")
set print $Data
do for [day=0:7] {
do for [i=0:24*4-1] {
print strftime(myTimeFmt,StartDateTime+day*24*3600 + i*15*60). \
",".sprintf("%.1f",74+6*sin(i/12.)+rand(0)*3)
}
if (day<7) { print ""; print ""} # 2 empty lines at the end of the day
}
set print
set timefmt myTimeFmt
set format x "%H:%M" timedate
set xtics 4*3600
stats $Data u 0 nooutput
set key top center
do for [i=0:STATS_blocks-1] {
plot $Data u (timecolumn(1,myTimeFmt)):3 index i w lp pt 7 ti strftime("%b %d", StartDateTime+i*24*3600)
}
set output
### end of code
结果: