Reputation: 57
I have a data file with 100 rows and about 400 columns. I am trying to plot each set of 2 columns (an x and y position for a single point) by iterating through the columns as done from Selecting a single row from a data file in gnuplot:
table_file="/tmp/gnuplot_tab.dat"
set table table_file
line_number = 1
data_file = "data.dat"
plot for [i=2:*:2] "<(sed -n '".line_number."p' ".data_file.")" u i:i+1
unset table
plot table_file
This works just fine for line_number = 1
but for, say, line_number = 79
it doesn't plot all the columns and says
Ending * iteration at 0
Why is this happening and how can I fix it? The end goal is to iterate through line_number
from 1 to 100 to plot the points as a function of time, but right now it's not even plotting all of certain lines.
I would appreciate it if you could explain your solution as well so I get a better understanding of gnuplot. Thank you!
EDIT: It's actually not working for the first line either! I realize only half the points are being plotted when I have line_number=1
. So then the problem is, why is this not plotting all of the points at all!
Upvotes: 0
Views: 476
Reputation: 25694
If I understood you correctly, your data looks basically like this:
r1 x(1,1) y(1,1) x(1,2) y(1,2) ... x(1,200) y(1,200)
r2 x(2,1) y(2,1) x(2,2) y(2,2) ... x(2,200) y(2,200)
r3 x(3,1) y(3,1) x(3,2) y(3,2) ... x(3,200) y(3,200)
...
r100 x(100,1) y(100,1) ... ... x(100,200) y(100,200)
and now you want to plot all x/y
pairs, e.g. like x(1,1)/y(1,1)
.
I don't think you need sed
for this. You can do it with gnuplot only. A simplified example (5 rows, 7 columns) below.
Code:
### plot number pairs
reset session
$Data <<EOD
11 12 13 14 15 16 17
21 22 23 24 25 26 27
31 32 33 34 35 36 37
41 42 43 44 45 46 47
51 52 53 54 55 56 57
EOD
stats $Data
M = STATS_records # number of datarows
N = STATS_columns # number of columns (be aware, gnuplot only checks the first row)
plot for [j=0:M-1] for [i=2:N-1:2] $Data u i:i+1 every ::j::j with points pt 7 notitle
### end of code
Result:
Upvotes: 1