Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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