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.

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.

  • Wouldn't with points leave out the connecting lines? – Michael Mrozek Oct 16 '15 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.