1
votes

I need to use gnuplot to plot wind direction values (y) against time (x) in a 2D plot using lines and points. This works fine if successive values are close together. If the values are eg separated by 250 degrees then I need to have a condition that checks the previous y value and does not draw a line joining the two points. This condition occurs when the wind dir is in the 280 degrees to 20 degrees sector and the plots are messy eg a north wind. AS the data is time dependent I cannot use polar plots except at a specific point in time. I need to show change in direction over time.

Basically the problem is:

plot y against x ; when (y2-y1)>= 180 then break/erase line joining successive points Can anyone give me an example of how to do this?

A sample from the data file is:

2014-06-16 16:00:00 0.000 990.081 0.001 0.001 0.001 0.001 0.002 0.001 11.868 308 002.54 292 004.46 00 
2014-06-16 16:10:00 0.000 990.047 0.001 0.001 0.001 0.001 0.002 0.001 11.870 303 001.57 300 002.48 00 
2014-06-16 16:20:00 0.000 990.014 0.001 0.001 0.001 0.001 0.002 0.001 11.961 334 001.04 314 002.07 00 
2014-06-16 16:30:00 0.000 990.014 0.001 0.001 0.001 0.001 0.002 0.001 11.818 005 001.18 020 002.14 00 
2014-06-16 16:40:00 0.000 990.014 0.001 0.001 0.001 0.001 0.002 0.001 11.725 332 001.14 337 002.26 00

and I want to plot column 12 vs time.

2
Why not you filter lines using awk utility and keep only required lines to be given as input to gnuplotStauz
Thanks Stauz - I need to retain all values, no data can be omitted. Its just the lines connecting points that are the problem.user3778424

2 Answers

1
votes

You can insert a filtering condition in the using statement and use a value of 1/0 if the condition is not fullfilled. In that case this point is not connect to others:

set timefmt '%Y-%m-%d %H:%M:%S'
set xdata time
unset key

y1 = y2 = 0
plot 'data.dat' using 1:(y1 = y2, y2 = $12, ($0 == 0 || y2 - y1 < 180) ? $12 : 1/0) with lines,\
     'data.dat' using 1:12 with points

With your data sample and gnuplot version 4.6.5 I get the plot:

enter image description here

Unfortunately, with this approach you cannot categorize lines, but only points and also the line following the 1/0 point aren't drawn.

A better approach would be to use awk to insert an empty line when a jump occurs. In a 2D-plot points from different data blocks (separated by a single new line) aren't connected:

set timefmt '%Y-%m-%d %H:%M:%S'
set xdata time
unset key

plot '< awk ''{y1 = y2; y2 = $12; if (NR > 1 && y2 - y1 >= 180) printf("\n"); print}'' data.dat' using 1:12 with linespoints
1
votes

In order to break the joining lines two conditional statements must be fulfilled and BOTH must include the newline statement printf("\n"):

plot '< awk ''{y1 = y2; y2 = $12; if (NR > 1 && y2 - y1 >= 180) printf("\n") ; if (NR > 1 && y2 -y1 <= 0) printf("\n"); print}'' /Desktop/plotdata.txt' using 1:12 with linespoints