4

I have a set of data in a text file (X,Y coordinates which are not sorted). I want to plot it using gnuplot and connect plotted points using lines.

I tried:

plot "a.txt" with lines

but it is connecting the first point to the second point and so on. I want it to just connect plotted points, not first to second, and so on.

Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233

2 Answers2

5

You will have to sort it before gnuplot reads it, to do what you want. gnuplot implicitly uses the order of data in the file as the information about connection between points. If the X coord is the coordinate you want to connect-the-dots by do this at the command line:

sort -n +0 -1 a.txt > b.txt

Use gnuplot to plot the contents of file "b.txt". Sometimes a gnuplot command like this will help you see the data better:

plot 'b.txt' using 1:2 with linespoints

That puts a visible mark (an X or triangle or something) at the actual (X,Y) pairs, as well as drawing lines between them.

2
plot "a.txt" with points pointtype 3 pointsize 2

I added pointtype and pointsize just to show other options.

Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233
opie
  • 21