我想用Gnuplot从输入文件的第4列和第10列中创建一个图表。
输入数据文件看起来是这样的(^^^^^符号仅突出显示相关列)。
^^^^^ ^^^^^
2017-05-29 15:41:29 10 512 0.215 4.332 0.430 1.451 1.158 0.199 7.785
2017-05-29 15:41:44 10 512 0.201 1.206 0.304 1.186 1.068 0.196 4.161
2017-05-29 15:42:00 10 512 0.195 1.223 0.301 1.206 1.055 0.204 4.184
2017-05-29 15:42:15 10 512 0.191 1.234 0.302 1.157 1.102 0.191 4.177
2017-05-29 15:42:30 10 512 0.196 1.233 0.297 1.246 1.129 0.206 4.307
...
Run Code Online (Sandbox Code Playgroud)
我要两个酒吧。一个显示列4的平均值,另一个显示列10的平均值。
是否可以让gnuplot计算列的平均值?
使用stats来计算您的数据集的统计值:
stats 'file.dat' using 5:10 nooutput
Run Code Online (Sandbox Code Playgroud)
平均值可用作变量STATS_mean_x和STATS_mean_y。这些计算必须在设置timefmt和xdata时间之前完成,因为统计信息在时间模式下不起作用。
还要注意,标记的第一列是第五列,因为日期和时间被计为gnuplot的两列。
reset
$data <<EOD
2017-05-29 15:41:29 10 512 0.215 4.332 0.430 1.451 1.158 0.199 7.785
2017-05-29 15:41:44 10 512 0.201 1.206 0.304 1.186 1.068 0.196 4.161
2017-05-29 15:42:00 10 512 0.195 1.223 0.301 1.206 1.055 0.204 4.184
2017-05-29 15:42:15 10 512 0.191 1.234 0.302 1.157 1.102 0.191 4.177
2017-05-29 15:42:30 10 512 0.196 1.233 0.297 1.246 1.129 0.206 4.307
EOD
stats $data using 5:10 nooutput
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
set autoscale xfix
plot $data u 1:5 w lp lt 1 t 'Col 5', '' u 1:(STATS_mean_x) w l lt 1 lw 2 t 'Avg col 5',\
'' u 1:10 w lp lt 2 t 'Col 10', '' u 1:(STATS_mean_y) w l lt 2 lw 2 t 'Avg col 10'
Run Code Online (Sandbox Code Playgroud)
为了显示有关数据的有意义的统计信息(不仅是平均值),可以使用boxplot绘图样式:
set style data boxplot
plot $data u (1):5:xtic('Col 5') title 'Col 5', '' u (2):10 title 'Col 10'
Run Code Online (Sandbox Code Playgroud)
您可以将计算所得的值保存stats到数据块中,set print并绘制该块:
stats $data using 5:10 nooutput
set print $mean
print STATS_mean_x
print STATS_mean_y
set style data boxes
set boxwidth 0.7
set style fill solid noborder
set yrange [0:*]
plot $mean using 0:1
Run Code Online (Sandbox Code Playgroud)