1
votes

I have some data, which I would like to plot in 3d and 2d Graphs. I do have a data file which has the following shape:

1 1 2
2 1 4
3 1 6
4 1 8

1 2 1
2 2 2
3 2 3
4 2 4

1 3 4
2 3 3
3 3 2
4 3 1

1 4 8
2 4 6
3 4 4
4 4 2

In this case the first column is x, the second one is y and the third one is the value. Actually I am using a file, which has 100 individual matrices, but I think that this example should be a little bit handier. :)

I made a 3d plot by using: splot "data.txt" using 1:2:3 with lines

In addition I would now like to make 2D plots in both directions. So something like

plot "data.txt" using 1:3 

using only the first matrix

and

plot "data.txt" using only the first line of 2:3 in every matrix

I found help at 1 in the section "How do I plot a part of data in a file?"

For the first case

plot "data.txt" every :::1:1 using 1:3 with lines

does seem to do the job

But for the second case I am not sure, how to manage the syntax the right way

plot "data.txt" every ::1   using 1:3 with lines

would not do what I expected. The plot is actually either empty or contains only one single data file.

1
I think your first example is wrong, it should be plot "data.txt" every :::0::0 using 1:3 with lines, note the zeros (which in gnuplot is the first element rather than 1) and the extra colon ":" in between zeros. This means "start plotting block zero and end with block zero". - Miguel
Yeah, you are right. My bad and thanks for this comment! :) - freeone

1 Answers

0
votes

Typing help every gives you guidelines on how to do this. I agree however that the every option is a bit awkward to use. This should do it:

plot "data.txt" every ::0::0   using 1:3 with lines

It means "plot elements zero to zero of each block". Element zero is the first element in gnuplot.

To be able to connect the points by lines, you need to use an external tool, such as awk:

plot "<awk -v p=0 'n==p; NF{n++} !NF{n=0}' data.txt" u 1:3 w l

where p=0 has the same effect as every ::0::0. This solution was already given here.