Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot Cumulative Column Question

Tags:

plot

gnuplot

I have some data.

#Time  Distance
 1   3
 2   5
 4   9
 8  11
12  17
14  20
16  34
20  40

I want to plot the cumulative distance wrt time in gnuplot ... (it should be easy) but I do not know how.

x

like image 613
Xofo Avatar asked Nov 13 '09 18:11

Xofo


3 Answers

For anyone still looking for this sort of thing, If your gnuplot version is 4.4 or newer, you can do the following:

a=0
#gnuplot 4.4+ functions are now defined as:  
#func(variable1,variable2...)=(statement1,statement2,...,return value)
cumulative_sum(x)=(a=a+x,a)
plot "test.dat" using 1:(cumulative_sum($2))
like image 106
mgilson Avatar answered Oct 03 '22 07:10

mgilson


If your data is in the file datafile, you can do a cumulative plot like so:

$ gnuplot
gnuplot> plot "datafile" smooth cumulative
like image 35
Daniel Patru Avatar answered Oct 03 '22 08:10

Daniel Patru


Assuming your data is in a file "test.txt", how about:

plot "<awk '{i=i+$2; print $1,i}' test.txt" with lines
like image 29
Mark Avatar answered Oct 03 '22 07:10

Mark