Gnuplot: line 0: no previous plot

Question:

I am trying to save the Gnuplot plot in PNG that I get with my SDR and a tool named rtl_power_fftw.

This command displays my plot on the screen but I want to save it in PNG:

rtl_power_fftw -f 900M:950M -n 10 -b 512 -q |
sed -u '/rtl-power-fftw/s/.*/ plot "-"/;/^$/{N;s/^n$/e/}' |
gnuplot -p

So after a few researches, I tried this:

rtl_power_fftw -f 900M:950M -n 10 -b 512 -q |
sed -u '/rtl-power-fftw/s/.*/ plot "-"/;/^$/{N;s/^n$/e/}' |
gnuplot -p -e "set term png; set output 'output.png'; replot; set term x11; set output"`

But this command gives me the following error: line 0: no previous plot when I use the command replot.

I would be very thankful if you can help me to save this plot in PNG, no matter the solution: command line, bash script or a mix of the two.

Asked By: gautudp

||

Answers:

The output from rtl_power_fftw -f 900M:950M -n 10 -b 512 -q apparently contains some GnuPlot commands, but we can’t know what they are. You want to modify the sed script to add the set term and set output commands at the beginning of the generated script.

rtl_power_fftw -f 900M:950M -n 10 -b 512 -q |
sed -u -e "1i\ set term png; set output 'output.png'" 
    -e '/rtl-power-fftw/s/.*/ plot "-"/;/^$/{N;s/^n$/e/}' |
gnuplot -p

What exactly works depends on your sed dialect. Perhaps on MacOS try

rtl_power_fftw -f 900M:950M -n 10 -b 512 -q |
sed -u -e "1i\
set term png; set output 'output.png'
" 
    -e '/rtl-power-fftw/s/.*/ plot "-"/;/^$/{N;s/^n$/e/}' |
gnuplot -p

(The -u option is probably quite unnecessary here, too.)

Answered By: tripleee
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.