tags:

views:

196

answers:

2

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

+1  A: 

I have a little experience with Gnuplot and I just pored over the documentation some. Unfortunately, I wasn't able to find a solution for generating a cumulative sum as you're plotting.

I think what you'll need to do is to massage your data with another program before letting Gnuplot at it. awk is one program that comes to mind, it's practically built for fiddling with columnar data. You can integrate this process into the plotting process by following these instructions.

Carl Smotricz
@Carl, sorry I inadvertently implemented your answer! I wish SO was a little faster with those "New Answer Posted" messages.
Mark
Don't be sorry, I'm flattered that my suggestion is what worked for you! Happy hacking.
Carl Smotricz
A: 

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

plot "<awk '{i=i+$2; print $1,i}' test.txt" with lines
Mark
Thanks ... I will try this.
Xofo
I found that THIS does not work cleanly if you have FLOATING POINT PAIRS. The error I got was:awk: (FILENAME=out.txt FNR=131) fatal: print to "standard output" failed (Broken pipe) ^ Bad data on line 1---
Xofo
Hmm, I just tried it with floats and it worked for me. What's on your line 1? Is it the header? Try maybe removing that.
Mark