Hi,
I've just realized a little enhancement to the datafile plotting related functions, that allows me to plot the cumulative sum of columns, rather than the plain column values, with this syntax:
plot 'file.txt' u 1:2 t 'raw', '' u 1:(sumcol(2)) t 'cumulative'
https://sourceforge.net/u/kefren/gnuplot/ci/bb0f7c9004e667c740ffaaad63188ef99be8f1f3/
So, in addition to the standard column(i) function, now I can use sumcol(i) to cumulatively sum up all the values in column i. Accumulators for different columns are kept in variables whose values are also accessible as CUMSUM_COL_1, CUMSUM_COL_2, ....
AFAIK, gnuplot currently allows one to do something similar with:
* either the new (statement,return-value) syntax, by which I can define a function accumulating the values first, then returning the cumulated value, but I have to be careful to pick different accumulator variables, and the syntax seems like more oriented towards programmers
* or with the "smooth cumulative" function.
Both of these I found more difficult to use, e.g., smooth cumulative (seems to me) goes mad when one of the columns in the datafile has date/format contents ("Need full using spec for x time data") or has a header line ("Bad data on line 1 of file").
I've just worked out this little enhancement as it seems to me the perfect way to support such a feature, and esp. to learn some of the gnuplot code internals :-).
Perhaps others might find this useful, thanks!
This should already be possible using
smooth cumulative. If you found problems with that, then it sounds like there might be bugs that should be fixed regardless of whether we go on to add your new functionality. Could we start with that, please? It might turn out that the program can already do exactly what you want.The presence of a header line is supposed to be handled by specifying
set datafile columnheadersbefore plotting. It is also possible to clue the program in to the header line by referring to it implicitly in the plot command, but try the simple solution first.I don't know what to make of the other error message you show without seeing exactly what you tried. Please show some sample data and the commands you used for plotting it.