Does anyone know how I can reuse inline data in Gnuplot, I've been googling it and can't find nothing everything suggests to input the data gain? Basically reuse the '-' file.
3 Answers
since I stumbled over this old question via Google...
There are two ways to having "inline data" (data in the gnuplot file):
- the special filename
'-'
, which reads the lines immediately following the plot command. This data can only be used once. - named datablocks with here documents, which can be reused:
$Data << EOD
0 0 0
1 1 1
2 2 4
3 3 9
4 4 16
EOD
plot $Data using 1:2 title 'linear' with linespoints, \
$Data using 1:3 title 'quadratic' with linespoints

- 15,896
- 2
- 36
- 63
-
1Yes, since gnuplot 5.0 (Jan 2015) you can use datablocks. If you want to use the identical `'-'` data twice you have to provide the data twice. There is an answer about this somewhere here on SO. If I find the link I will add it. – theozh Aug 20 '22 at 10:28
Using blockdata
is most useful see Gnuplot: Histogram plots with inline data
However:
Reading gnuplot
embedded help:
gnuplot> help plot datafile special-filenames
states:
... The special filename
'-'
specifies that the data are inline; ... If you use'-'
... you may need to enter the data more than once. ... A blank filename ('') specifies that the previous filename should be reused. ... (If you use both'-'
and''
on the sameplot
command, you'll need to have two sets of inline data, as in the example above.)
so you can do:
gnuplot> plot '-' using 1:2, '' using 1:3
input data ('e' ends) >
and then paste the same data twice:
0.000 0 0
0.001 104 51
0.002 202 101
0.003 298 148
0.0031 290 149
0.004 289 201
0.0041 291 209
0.005 310 250
0.010 311 260
0.020 280 240
e
input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) >
0.000 0 0
0.001 104 51
0.002 202 101
0.003 298 148
0.0031 290 149
0.004 289 201
0.0041 291 209
0.005 310 250
0.010 311 260
0.020 280 240
e
input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) > input data ('e' ends) >
gnuplot>
environment under test:
linuxuser@ubuntu:~$ uname -a
Linux ubuntu 4.15.0-74-generic #84-Ubuntu SMP Thu Dec 19 08:06:00 UTC 2019 i686 i686 i686 GNU/Linux
linuxuser@ubuntu:~$ gnuplot -V
gnuplot 5.2 patchlevel 2

- 11
- 2
in place of a bare replot
, you can use refresh
if you're using gnuplot 4.3 or newer. If you actually want to add more data to be plotted, I think you're out of luck.
e.g.
plot '-' u 1:2
1 2
2 3
e
set label "Hello World!" at 1.5,2.5
refresh

- 300,191
- 65
- 633
- 696