Gnuplot reads weather data from a huge file called file.dat
and plots the weather data for a given date and time.
But if there is no data for the given date and time (xrange), gnuplot crashes.
How can I tell gnuplot, if there is no data for a given date and time, display a text in the output image?
("There is no data available, I am sorry")
The error, if there is no data available:
line 0: all points y2 value undefined!
The script.dem
file, which is loaded by gnuplot:
reset
#SET TERMINAL
set term svg
set output 'temp-verlauf.svg'
set title "Temperaturverlauf"
#Axes label
set xlabel "Messzeitpunkt"
set ylabel "Luftfeuchte/Temperatur"
set y2label "Luftdruck"
#Axis setup
set xdata time # x-Achse wird im Datums/Zeitformat skaliert
set timefmt "%d.%m.%Y\t%H:%M:%S" # Format Zeitangaben yyyy.mm.dd_hh:mm:ss
set format x "%H:%M" # Format für die Achsenbeschriftung
#Axis ranges
set yrange [0:60] # die y-Achse geht von:bis
#Tics
set ytics nomirror
set y2tics nomirror
#OTHER
set datafile separator "\t"
set xrange ["06.11.2014 14:00:00":"07.11.2014 21:00:00"]
plot \
"file.dat" every 10 using 1:5 title "Luftfeuchte" with lines, \
"file.dat" every 10 using 1:6 title "Temperatur" with lines, \
"file.dat" every 10 using 1:7 title "Luftdruck" with lines axes x1y2, \
"file.dat" every 10 using 1:17 title "Niederschlagsintensitaet Synop (4677)" with lines
EDIT
Thanks to user "bibi".
He had the good idea to let gnuplot plot -1 to have data if there is nothing avaible in file.dat.
The script will look like that:
reset
#SET TERMINAL
set term svg
set output 'temp-verlauf.svg'
set title "Temperaturverlauf"
#Axes label
set xlabel "Messzeitpunkt"
set ylabel "Luftfeuchte/Temperatur"
set y2label "Luftdruck"
#Axis setup
set xdata time # x-Achse wird im Datums/Zeitformat skaliert
set timefmt "%d.%m.%Y\t%H:%M:%S" # Format Zeitangaben yyyy.mm.dd_hh:mm:ss
set format x "%H:%M" # Format für die Achsenbeschriftung
#Axis ranges
set yrange [0:60] # die y-Achse geht von:bis
#Tics
set ytics nomirror
set y2tics nomirror
#OTHER
set datafile separator "\t"
set xrange ["06.11.2014 14:00:00":"07.11.2014 21:00:00"]
plot \
-1 axes x1y2, \
-1 axes x1y1, \
"file.dat" every 10 using 1:5 title "Luftfeuchte" with lines, \
"file.dat" every 10 using 1:6 title "Temperatur" with lines, \
"file.dat" every 10 using 1:7 title "Luftdruck" with lines axes x1y2, \
"file.dat" every 10 using 1:17 title "Niederschlagsintensitaet Synop (4677)" with lines
The simplest solution it came to my mind is to draw an horizontal line outside the plotting region (-1 is ok since you have set yrange [0:60]
):
plot \
-1, \
"file.dat" every 10 using 1:5 title "Luftfeuchte" with lines, \
"file.dat" every 10 using 1:6 title "Temperatur" with lines, \
"file.dat" every 10 using 1:7 title "Luftdruck" with lines axes x1y2, \
"file.dat" every 10 using 1:17 title "Niederschlagsintensitaet Synop (4677)" with lines
Moreover the gnuplot internal variable GPVAL_ERRNO
will be non-zero if something weird happened, you might check that and print a banner on screen.