1
votes

I'm trying to plot "x;y1;y2" data from an inline file:

set xdata time
set timefmt "%Y-%m-%dT%H:%M:%S"
set format x "%H:%M:%S"
set datafile separator ";"
set yrange [0:]
plot '-' index 0 using 1:2 with linespoints t 'before', '-' index 0 using 1:3 with linespoints t 'after'
2015-11-05T00:42:32;0.690000;0.690000
2015-11-05T00:43:34;0.690000;0.690000
2015-11-05T00:44:35;0.690000;0.690000
2015-11-05T00:45:36;0.690000;0.690000
2015-11-05T00:46:37;0.690000;0.690000
2015-11-05T00:47:38;0.690000;0.690000
2015-11-05T00:48:38;0.690000;0.690000
2015-11-05T00:49:40;0.690000;0.690000
e

gnuplot - however - complains the second part of having no data. While repeating the data such as

set xdata time
set timefmt "%Y-%m-%dT%H:%M:%S"
set format x "%H:%M:%S"
set datafile separator ";"
set yrange [0:]
plot '-' index 0 using 1:2 with linespoints t 'before', '-' index 0 using 1:3 with linespoints t 'after'
2015-11-05T00:42:32;0.690000;0.690000
2015-11-05T00:43:34;0.690000;0.690000
2015-11-05T00:44:35;0.690000;0.690000
2015-11-05T00:45:36;0.690000;0.690000
2015-11-05T00:46:37;0.690000;0.690000
2015-11-05T00:47:38;0.690000;0.690000
2015-11-05T00:48:38;0.690000;0.690000
2015-11-05T00:49:40;0.690000;0.690000
e
2015-11-05T00:42:32;0.690000;0.690000
2015-11-05T00:43:34;0.690000;0.690000
2015-11-05T00:44:35;0.690000;0.690000
2015-11-05T00:45:36;0.690000;0.690000
2015-11-05T00:46:37;0.690000;0.690000
2015-11-05T00:47:38;0.690000;0.690000
2015-11-05T00:48:38;0.690000;0.690000
2015-11-05T00:49:40;0.690000;0.690000
e

does the job, I hoped, that index 0 had selected the right dataset. I also tried to leave out the second "file"name to use the last file again.

Is there a better way of using the same inline data again without repeating?

1

1 Answers

4
votes

Since version 5.0 gnuplot has a new "named data block" structure (like a heredoc), which allows you to save inline data once and use it as often as you want:

$data <<EOD
2015-11-05T00:42:32;0.690000;0.690000
2015-11-05T00:43:34;0.690000;0.690000
2015-11-05T00:44:35;0.690000;0.690000
2015-11-05T00:45:36;0.690000;0.690000
2015-11-05T00:46:37;0.690000;0.690000
2015-11-05T00:47:38;0.690000;0.690000
2015-11-05T00:48:38;0.690000;0.690000
2015-11-05T00:49:40;0.690000;0.690000
EOD

set xdata time
set timefmt "%Y-%m-%dT%H:%M:%S"
set format x "%H:%M:%S"
set datafile separator ";"
set yrange [0:]
set style data linespoints
plot $data using 1:2 t 'before', '' using 1:3 t 'after'