1

I'm using gnuplot to plot some data in terminal, but, I can't understand what it is I'm actually plotting..

The data that I am plotting is as follows:

0 0 
0 0 
0 0 
0 0 
0 0 
0 0 
0 0 
-4.30073 11.0396 
0.597324 0.717791 
0.994737 0.0914964 
0.461595 -0.0463647 
0.823025 -0.028436 
0.175018 -0.325786 
-0.162711 -0.095196 
0.162538 -0.0879469 
-0.207604 -0.0375564 
-0.428694 0.406283 
-0.509088 -0.863523 
-1.98853 -0.834989 
-0.81263 -0.44062 

And the result is as follows:

enter image description here

Is gnuplot therefore just plotting the first columns of data, or performing a calculation on the data in order to plot?

The command that I'm using is as follows:

plot './data.txt' using 2 with lines

Any help would be greatly appreciated

Ahmed Salman Tahir
  • 1,783
  • 1
  • 17
  • 26
Phorce
  • 4,424
  • 13
  • 57
  • 107

2 Answers2

3

It's just plotting second column of your datafile. (zeroes and after them goes spike to 11, gnuplot starts indexing from 1). For plotting just first column you can use:

plot './data.txt' using 1 with lines

Or if you want to plot XY graph just type one of following examples:

#simplest case, uses first column for X axis and second for Y
plot './data.txt' with lines

#Same as previous, but can be helpful if there more than two columns in datafile
plot './data.txt' using 1:2 with lines

#Uses second column for X and first for Y
plot './data.txt' using 2:1 with lines

Hope this will answer your question.

user3234005
  • 342
  • 1
  • 2
  • 10
  • Hey, when I use the `plot './data.txt' with lines` I get the following error: `Bad data on line 3`? – Phorce Feb 26 '14 at 14:37
  • 1
    Hmm. This is strange. Check your file if there is no stray character symbols on line 3. I had copied data from your post and all worked well. So you can try to create new file and copypaste data into it and if it will work you can just look into diff between new and old versions. – user3234005 Feb 26 '14 at 14:54
  • Ahh, right, that makes more sense. I had words at the top of the file! Ok, that is sorted! The columns, are just the interesting data of this file - Are there any ways to just plot the columns, or, should I just use the command that I already had? – Phorce Feb 26 '14 at 15:46
  • 1
    Do you want plot two lines one for each column? Then this [link](http://stackoverflow.com/questions/16073232/gnuplot-plotting-a-file-with-4-columns-all-on-y-axis) should help. – user3234005 Feb 26 '14 at 16:56
1

If there is only one data column given, gnuplot takes that as the y data. The x data are just the indices, equivalent to the row number of your input file. (It appears you set a lower x limit, because data at x=1 and x=2 aren't plotted.)

Since you specified using 2, the first data column is completely ignored, and only the second column used, with the indices as the x values.

For reference, the documentation says "Only one column (the y value) need be provided. If x is omitted, gnuplot provides integer values starting at 0. ".