Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Make gnuplot ignore missing data

1,738 views
Skip to first unread message

Steinar Midtskogen

unread,
Aug 14, 2010, 1:32:20 PM8/14/10
to
I run gnuplot in a cron script to plot many graphs to different svg
files. Occationally there will be nothing to plot for some graphs.
I've defined an xrange, the yrange is auto and sometimes there are no
y values within the xrange. So there is nothing to plot. The trouble
is that gnuplot *exits* once it runs into this problem, so gnuplot
wont plot any of the graphs that it was supposed to plot after it
encountered the problem. Whether gnuplot skips the plotting
altogether (doesn't update the file), picks any yrange or it doesn't
plot a y scale, or plots "no data", doesn't matter. I just want
gnuplot to plot all the graphs that have data.

I could rewrite the script so it runs one instance of gnuplot per
graph, but that's pretty tedious work.

I tried to google a bit, but the only solution I found was to set the
yrange, which I don't want to do (unless there is a way to define the
yrange only for cases when the y values are missing...).

I'm using version 4.2 patchlevel 2.

--
Steinar ; NIL DIFFICILE VOLENTI ; http://latinitas.org ; http://voksenlia.net

sfeam

unread,
Aug 14, 2010, 2:24:10 PM8/14/10
to
Steinar Midtskogen wrote:

> I run gnuplot in a cron script to plot many graphs to different svg
> files. Occationally there will be nothing to plot for some graphs.
> I've defined an xrange, the yrange is auto and sometimes there are no
> y values within the xrange. So there is nothing to plot. The trouble
> is that gnuplot *exits* once it runs into this problem, so gnuplot
> wont plot any of the graphs that it was supposed to plot after it
> encountered the problem.


This is not correct as stated. Gnuplot does not exit, it simply returns
to the command prompt. Or in the case of a script, it returns to the
next line of the script.
Here is a simple example using version 4.2

[1] cat test.bug
set term svg
set output 'bug.svg'
plot '1.txt','2.txt','3.txt'
print "Finished the plot"

[2] gnuplot_4.2.0 test.bug
"test.bug", line 3: warning: Skipping unreadable file "2.txt"
Warning: empty x range [0:0], adjusting to [-1:1]
Finished the plot
[3]

The output file does contain a plot of 1.txt and 3.txt,
and execution continues with the next line of the script.
So I think something else must be going on in your case.
Perhaps you could give more information?

Steinar Midtskogen

unread,
Aug 14, 2010, 5:01:46 PM8/14/10
to
[sfeam <sf...@users.sourceforge.net>]

Sure. By "no y values within the xrange" I didn't mean that the file
didn't exist, just that it doesn't contain any y values within the
range set by the xrange. An example: let's say that the xrange is the
latest 24 hours and the file is a log file which for some reason
wasn't updated in that period.

I should also clarify that by writing to several svg files, it means
that I'm using several plot commands. If one fails in this way,
gnuplot wont process the next ones. In your example gnuplot will
still have something to plot since 1.txt and 3.txt exist.

So reworking your example a bit, it can be reproduced this way:

$ cat test.pl
set term svg
set xrange [ 0 : 10 ]
set output 'bug1.svg'
plot '1.txt'
set output 'bug2.svg'
plot '2.txt'
set output 'bug3.svg'
plot '3.txt'
print "Finished the plot"

$ cat 1.txt
-3 1
-2 2
-1 3

$ cat 2.txt
1 1
2 2
3 3

$ cat 3.txt
1 3
2 2
3 1

$ gnuplot test.pl

plot '1.txt'
^
"test.pl", line 4: all points y value undefined!

$ ls bug2.svg
ls: cannot access bug2.svg: No such file or directory


The problem: gnuplot exits after "plot '1.txt'", so bug2.svg and
bug3.svg aren't made. If "plot '1.txt'" is executed last, then
bug2.svg and bug3.svg will be generated.

--
Steinar

sfeam

unread,
Aug 14, 2010, 8:24:10 PM8/14/10
to
Steinar Midtskogen wrote:


OK. I see. It's not that the program invariably exits on error.
But yes, if it emits an error rather than a warning, it then looks
to see if it is executing from inside a file. If so, it stops
taking input from the current file and either moves on to the next
(e.g. gnuplot a.pl b.pl c.pl) or returns to the calling level
(if the error happened inside a "load 'a.pl'" command).

The simplest way to work around this is to provide the input in a
non-file stream:

[1] gnuplot < test.pl
gnuplot> plot '1.txt'
^
line 0: all points y value undefined!
Finished the plot

[2] wc bug?.svg
0 0 0 bug1.svg
92 390 5288 bug2.svg
92 390 5288 bug3.svg
184 780 10576 total

Steinar Midtskogen

unread,
Aug 15, 2010, 1:20:18 AM8/15/10
to
[sfeam <sf...@users.sourceforge.net>]

> OK. I see. It's not that the program invariably exits on error.
> But yes, if it emits an error rather than a warning, it then looks
> to see if it is executing from inside a file. If so, it stops
> taking input from the current file and either moves on to the next
> (e.g. gnuplot a.pl b.pl c.pl) or returns to the calling level
> (if the error happened inside a "load 'a.pl'" command).

OK. It may be an error to try to autoscale no data, but stopping
taking input from the current file is a bit harsh, I think.

> The simplest way to work around this is to provide the input in a
> non-file stream:
>
> [1] gnuplot < test.pl

Thanks!

--
Steinar

0 new messages