I would like a Perl script to display a simple gnuplot graph. I don't want to store any data in a file, I want to use a gnuplot one-liner such as:
gnuplot -p <(echo -e 'plot "-"\n1 1\n2 3\n3 1.7\n4.5 5\ne')
That displays the points (1, 1), (2, 3), (3, 1.7) and (4.5, 5).
In a Perl script, I tried things like
$plotString = "\"<(echo -e 'plot \\\"-\\\"\\n";
$plotString .= "1 1\\n2 3\\n3 1.7\\n4.5 5\\ne')\"";
system('gnuplot -p ' . $plotString);
but I get the following error:
-e plot "-"
^
"<(echo -e 'plot "-"\n1 1\n2 3\n3 1.7\n4.5 5\ne')", line 1: invalid command
This error surprises me because the string passed to system()
, as quoted in the error message, is apparently correct.
Any idea how to modify $plotString
so system()
would correctly interpret the gnuplot command?
Secondary question: how to draw the graph with lines
? (I couldn't get the gnuplot one-liner to do it, even outside Perl.)
Edit: My OS is Ubuntu 16.04.