我有多个像这样的 CSV 文件(只有一列):
3
4
2.3
0.1
Run Code Online (Sandbox Code Playgroud)
现在我想创建一个包含<filename>:<sum of the column>.
但目前我很难总结一个专栏:
plot 'data1.txt' using 0:(sum [col = 0:MAXCOL] (col)) with linespoint;
Run Code Online (Sandbox Code Playgroud)
您显示的命令是对每行而不是每列求和。
(1) 如果您可以在将 csv 文件输入到 gnuplot 之前转置行/列,则此命令将生成接近您要求的绘图。请注意,MAXCOL 实际上是原始数据文件中的行数(而不是列数)
set boxwidth 0.5
set style fill solid
plot 'transpose_of_original' using 0:(sum [col=0:MAXCOL] col) with boxes
Run Code Online (Sandbox Code Playgroud)
(2) 或者,您可以通过首先累加总和然后绘制它来进行求和 gnuplot
# get number of columns
stats 'data1.txt' nooutput
NCOL = STATS_columns
array SUM[NCOL]
# get sum for each column
do for [col=1:NCOL] {
stats 'data1.txt' using col nooutput
SUM[col] = STATS_sum
}
# Now we plot the sums in a bar chart
set style fill solid
set boxwidth 0.5
set xlabel "Column"
set ylabel "Sum"
plot SUM using 1:2 with boxes
Run Code Online (Sandbox Code Playgroud)