I would like to re-use the same stdin data for two or more lines in code like
plot '-' using 0:1 with lines, '' using 0:1:2 with yerrorbars
3.4 0.1
2.9 0.2
8.8 0.5
2.1 0.7
This code would work if instead of stdin I store all data into a file and then plot from this data file. However, plotting from stdin, the code behaves exactly like
plot '-' using 0:1 with lines, '-' using 0:1:2 with yerrorbars
3.4 0.1
2.9 0.2
8.8 0.5
2.1 0.7
(i.e. '-'
instead of ''
) and gives a warning “Skipping data file with no valid points” instead of printing error bars to the line-plotted data.
Obviously, the plot can be made to work if I duplicate the data on stdin
plot '-' using 0:1 with lines, '' using 0:1:2 with yerrorbars
3.4 0.1
2.9 0.2
8.8 0.5
2.1 0.7
e
3.4 0.1
2.9 0.2
8.8 0.5
2.1 0.7
but I find this unsatisfactory, because then ""
means the same thing
as "-"
for stdin. Of course, what I am looking for would require gnuplot to silently store the most recent data segment from stdin for potential re-use, which is probably in most cases not necessary. Still I do not think it is a huge burden on efficiency. So perhaps there is an option or a different use of gnuplot syntax that I do not know?
Why not using a datablock? I never use '-'
, exactly because of this issue. You can clear the data with undef $Data
. Check help datablocks
and help undef
.
Code:
### re-use of data from a datablock
reset session
$Data <<EOD
3.4 0.1
2.9 0.2
8.8 0.5
2.1 0.7
EOD
set xrange [-0.2:3.2]
plot $Data u 0:1 w l, '' using 0:1:2 w yerrorbars
### end of code
Result: