2
votes

I plot a CSV file in scatter-plot with connecting lines with gnuplot using the following command:

set style line 1 lc rgb '#0060ad' lt 1 lw 1 pt 7 pi -1 ps 1
set pointintervalbox 1.25

plot "values.csv" using 1:2 with lp ls 1 

It looks great, but what I get is an opened polygon because gnuplot doesn't draw the line connecting the first point and the last.

How do I get gnuplot to connect the first and last points so I get a closed polygon?

1

1 Answers

2
votes

The easiest way to do this is as suggested in the comments by modifying your data file. However, if you want to get fancy you can do some awk on-the-fly preprocessing to append the first data point to the end of the file.

Consider the following data file:

# Some comment for the sake of generality
0 0
1 1
2 1
2 0

Which looks like this without any processing (e.g., plot "data" w l):

enter image description here

We remove comments and add the first line to the end of the file:

datafile = "< grep -v '#' data | awk '{if(NR==1) {i += 1; temp = $0; print \
$0;} else {i += 1; print $0;}} END {print temp}'"

plot datafile w l

enter image description here