How to plot data without a separate file by specifying all points inside the Gnuplot script?

You can use the syntax for inline data - filename '-'.

The following example produces a simple plot in a GIF image (bash script):

gnuplot << EOF
set terminal gif
set output 'plot1.gif'
plot '-' using 1:2
        1 10
        2 20
        3 32
        4 40
        5 50
        e
EOF

Gnuplot 5.0.1 datablocks

main.gnuplot

$data << EOD
1 1
2 4
3 9
4 16
EOD

plot "$data" \
  with linespoints \
  title "my data"

Convert to PNG:

gnuplot -e 'set terminal png' -e 'set output "main.png"' main.gnuplot

Output:

enter image description here

This method is a bit more versatile than '-' as it makes it easier to reuse the same data multiple times, including on the same plot command: How to embed multiple datasets in a gnuplot command script for a single plot command?

Version 5 is available on Ubuntu 15.04, or compile from source with: https://askubuntu.com/a/684136/52975

You may also be interested in the + and ++ special file names when plotting with functions.

Tested on Ubuntu 18.10, gnuplot 5.2.


Example from using shell with pipeline,

gnuplot -p <(echo -e 'plot "-"\n1 1\ne')

Tags:

Gnuplot