2

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

2
  • you want to send data as columns? it is not clear how you want to send it, can you show it with a proper example? Commented Mar 28, 2017 at 7:18
  • I would like to plot data generated by my for loop and pipe them directly into gnuplot (if it is possible). My issue is that I can't store this data flow like a standard dat file (i.e with the classic way of using gnuplot). Commented Mar 28, 2017 at 7:26

1 Answer 1

2

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"
Sign up to request clarification or add additional context in comments.

1 Comment

@youpilat13: Note that Gnuplot also supports data manipulation, you can for example achieve a similar result like this: seq 100 | gnuplot -p -e 'plot "-" u 1:($1**2) w l'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.