是否可以让gnuplot计算列的平均值?

时间:2017-05-30 15:09:46

标签: gnuplot

我想用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
...

我想要两个酒吧。一个显示第4列的平均值,另一个显示第10列的平均值。

是否可以让gnuplot计算列的平均值?

1 个答案:

答案 0 :(得分:4)

1。绘制所有数据点并可视化平均值

使用stats计算数据集的统计值:

stats 'file.dat' using 5:10 nooutput

平均值可用作变量STATS_mean_xSTATS_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'

enter image description here

2。可视化有关列的统计信息

为了显示有关数据的有意义的统计信息(不仅是平均值),您可以使用boxplot绘图样式:

set style data boxplot
plot $data u (1):5:xtic('Col 5') title 'Col 5', '' u (2):10 title 'Col 10'

enter image description here

3。仅绘制具有平均值

的框

您可以将使用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

enter image description here