The Computer Oracle

In gnuplot, how to plot with lines but skip missing data points?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Realization

--

Chapters
00:00 In Gnuplot, How To Plot With Lines But Skip Missing Data Points?
00:41 Accepted Answer Score 18
01:03 Answer 2 Score 11
01:25 Answer 3 Score 2
02:13 Answer 4 Score 0
02:52 Thank you

--

Full question
https://superuser.com/questions/440947/i...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#gnuplot

#avk47



ACCEPTED ANSWER

Score 18


Put an empty record (blank line) where there is no data. From the docs:

Single blank records designate discontinuities in a plot; no line will join points separated by a blank records (if they are plotted with a line style).




ANSWER 2

Score 11


You can use any string that is not a number as value for the missing data points or explicitly specify a missing data string using the set datafile missing command.

If you then plot the lines using

plot "vikt_ma.txt" using 1:($2) with lines title "first line"

then Gnuplot will leave a gap.




ANSWER 3

Score 2


You can also do something like this to automatically create gaps when the distance between x values exceeds some threshold:

previous=1
current=1
shift(x) = (previous=current, current=x)
yornothing(x,y) = ( shift(x), abs(x-previous)<7200?y:sqrt(0/0))

plot "file.dat" using 1:(yornothing($1,$2)) with lines

You'll need to adjust the initial values of "previous" and "current", and the threshold ("7200" in the example above).

The function "yornothing" uses the function "shift" to store one previous value of x. Each time yornothing is called, it returns either the value of y or "0/0", depending on whether the absolute value of the difference between x and its previous value exceeds the threshold.

A value of 0/0 tells gnuplot to ignore that point.




ANSWER 4

Score 0


Hej!

Your post is already older but I have a similar problem. I'm using time data though as the input (following format: 2022-08-01,00:03:03) which is imported with the following settings:

   set xdata time
   set timefmt '%Y-%m-%d,%H:%M:%S'
   set format x "%H:%M"

I'd like to skip lines if the spacing is more than, say, 15 minutes between timestamps. How can the yornothing-function be adapted to work with time in the above way?

Thanks, help appreciated!

JaJo