2
votes

I'm using bash to feed gnuplot from a script. How you pop up only one window? Let say you run

#!/bin/bash 
for((i=1;i<6;i++)) do
  echo "plot sin(x)"
done | gnuplot -persist

you will get 5 windows of the same plot. Is there an option to get only one?


There was a mistake above. That wasn't exactly the kind of run-time i'm doing. Is more like runing the next script, say, 5 times

#!/bin/bash 
echo "plot sin(x)"    

I just realized that what I want to do is kill the latest gnuplot process before make the new one.

Sorry for that. I'm sooo tired today :D

4
If the plot isn't changing, why are you sending the information 6 times? (I'm having a hard time coming up with a situation where this makes sense...) - mgilson
Also, I've tried your script and it worked fine for me (produced only 1 plot (bash 4.1.5 Ubuntu Linux)). What version of bash are you using? What OS? - mgilson
You can kill the gnuplot windows with killall gnuplot_x11 if you're using the x11 terminal. I'm not sure if -persist works with other terminals...(tested on OS X) - mgilson

4 Answers

3
votes

the gnuplot x11 terminal uses a separate program called gnuplot_x11 for displaying the results. From the help

The `xlib` terminal driver supports the X11 Windows System.  It generates
 gnuplot_x11 commands, but sends them to the output file specified by
 `set output '<filename>'`. `set term x11` is equivalent to
 `set output "|gnuplot_x11 -noevents"; set term xlib.`
 `xlib` takes the same set of options as `x11`.

So, if you want to kill plots that are remaining after a gnuplot -persist, it should suffice to killall gnuplot_x11.

2
votes

You might be interested in the iteration capabilities available in newer versions of Gnuplot (see the section Iteration in the user's guide)

2
votes

What about the following:

  echo `for((i=1;i<6;i++))
  do
    echo 'plot sin(x)'
  done` | gnuplot -persist
1
votes

In one script one can

    echo "set grid" > gpfile
    tail -f  gpfile | gnuplot  '-'

then in another process one can write any gnuplot commands into the gpfile

    echo "plot \"whatever\" " >> gpfile
    sleep 3
    echo "replot" >> gpfile

...etc

Its useful for realtime process control display, where some status file

is being updated at intervals.