我试图在单个图表上绘制多条线,其中每条线的数据位于单独的数据文件中。数据是日期/时间和实数。 我可以绘制单行/数据文件,但无法正确绘制多行/数据文件(共享相同的轴)。
我有几个包含日期/时间和值行的数据文件,如下所示:
输出0.tsv:
2023-10-13 08:05:22 3.77362878455463
2023-10-13 08:16:38 3.77371398500197
2023-10-13 08:27:54 3.77415538319968
2023-10-13 08:36:29 3.77337830143226
2023-10-13 08:46:20 3.7721485759286
...
输出1.tsv:
2023-10-13 08:06:12 9.58516483516484
2023-10-13 08:17:28 9.58519607843137
2023-10-13 08:28:44 9.5859382655561
2023-10-13 08:37:19 9.58436979727744
2023-10-13 08:47:09 9.58482994861757
...
我想在同一个图表上绘制这两个图,所以我使用这些 gnuplot 命令:
set terminal qt size 1300,600
set grid
set mxtics 4
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
set datafile sep ' '
set xtics format "%F %R" rotate
plot "output1.tsv" using 1:3 title "computer A" with lines,\
"output0.tsv" using 1:3 title "computer B" with lines
然而,这显示了一个带有两条水平线的图表(似乎将每个文件的第一个值显示为整个图表中的常量)。标题是正确的。
如果我只显示一个数据文件:
set terminal qt size 1300,600
set grid
set mxtics 4
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
set datafile sep ' '
set xtics format "%F %R" rotate
plot "output1.tsv" using 1:3 title "computer A" with lines
然后这将按预期工作,显示折线图,其值在所需的时间段(和标题)中变化。
在尝试将多个数据文件的值绘制为同一图表上的单独线条时,我做错了什么? (共享相同的轴 - X 是日期/时间,Y 是值)。
注意:两个文件的日期/时间不相同 - 数据表示在一段时间内从一组计算机记录的指标,每台计算机的记录都在其自己的文件中,并且该组循环播放,每台计算机按顺序记录。所以我录制电脑 A,然后录制 B,然后再次录制 A,然后再次录制 B,等等。每次录制需要几秒钟。
我在现代 Ubuntu Linux 变体上使用 gnuplot 5.4 patchlevel 2。
正如 @MartinBrown 在评论中已经指出的那样:在给定的垂直终端尺寸仅为 600 像素的情况下,看起来变化太小而无法被注意到。 完整数据文件中 y 值的完整范围是多少?
在您的示例数据中,更改是 <0.01 in a y-scale of [0:10] with a vertical terminal size of 600 pixels. So, changes will hardly be visible.
为了使极小的变化可见,您可以绘制例如与平均值的偏差。
脚本:
### plot deviations from mean value
reset session
$Data1 <<EOD
2023-10-13 08:05:22 3.77362878455463
2023-10-13 08:16:38 3.77371398500197
2023-10-13 08:27:54 3.77415538319968
2023-10-13 08:36:29 3.77337830143226
2023-10-13 08:46:20 3.7721485759286
EOD
$Data2 <<EOD
2023-10-13 08:06:12 9.58516483516484
2023-10-13 08:17:28 9.58519607843137
2023-10-13 08:28:44 9.5859382655561
2023-10-13 08:37:19 9.58436979727744
2023-10-13 08:47:09 9.58482994861757
EOD
stats $Data1 u 3 name "Data1" nooutput # get the mean value
stats $Data2 u 3 name "Data2" nooutput
myTimeFmt = "%Y-%m-%d %H:%M:%S"
set format x "%H:%M" timedate
set grid x,y
set key title "Deviations from\nmean value"
set xzeroaxis lw 1.5 lc "web-green"
plot $Data1 u (timecolumn(1,myTimeFmt)):($3-Data1_mean) w lp pt 7 lc "red" ti sprintf("Data1: %.4f",Data1_mean), \
$Data2 u (timecolumn(1,myTimeFmt)):($3-Data2_mean) w lp pt 7 lc "blue" ti sprintf("Data2: %.4f",Data2_mean)
### end of script
结果: