0

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!

2
  • That command should work (tested here on a local file accessed by name). My best guess is that your sed filter is returning a data stream that cannot be plotted, and the iteration stops as soon as it encounters a plot with no valid points in it. Commented Apr 30, 2019 at 16:34
  • Try adding to the end of the plot for... line an extra with table. This should simplify what is written to table_file. You should also look at that file to see what it contains. Commented Apr 30, 2019 at 17:14

1 Answer 1

1

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:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Do you happen to know a way to call to the last column? The * wasn't working, is there instead a certain variable or function like last_column = thing_that_returns_last_column ? My simulation data changes the amount of points in every run, so it'd be easier to just have something that works always.
I also have problems with * for scanning the columns. I guess it's buggy, it's probably working on some systems but crashing or hanging on other systems. Well, you can do stats $Data and take the variable STATS_columns. But be aware STATS_columns only checks the number of columns in the first (data)row.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.