Reputation:
I have input that I generate directly from Bash (representing y=x^2
)
for((i=0;i<10;i++)); do printf "%3d %3d\n" $((i)) $((i*i)); done
I would like to plot these input data with gnuplot and using if possible with a pipe.
I tried to do naively :
for((i=0;i<100;i++)); do printf "%3d %3d\n" $((i)) $((i*i)); done < gnuplot -e "plot u 1:2 w l"
but this can't work because I printf sequentially
the values (i,i^2)
.
I tried to use echo -e
(before the redirection "<
" of gnuplot) :
echo -e $(for((i=0;i<100;i++)); do printf "%3d %3d\n" $((i)) $((i*i)); done )
on above command (for loop
) to find a way to store the 2 entire colums of values and then pass them to gnuplot command, but with this solution, I don't produce 2 columns (I get only a row of data).
Someone could help me to plot the generated data with gnuplot using a pipe (i.e with only one command line)
Thanks for your help
Upvotes: 2
Views: 1764
Reputation: 48390
You must pipe the data to gnuplot with for ... | gnuplot -e ...
and you must tell gnuplot to read from stdin with plot '-'
:
for((i=0;i<100;i++)); do printf "%3d %3d\n" $((i)) $((i*i)); done | gnuplot -e "set terminal pngcairo; set output 'blubb.png'; plot '-' u 1:2 w l"
Upvotes: 2