Reputation: 1
I am successfully gnuplotting to an X window in Python on a RPi.
The python code gathers data, periodically appends it to a CSV file and plots the CSV file with: ('set terminal gif medium size 1100,600 background "#e7e7ff"\n') ('set output "/home/pi/pp/plotdata.gif"\n') This overwrites the gif and FTPs the gif file periodically. The gif file is FTP'd to a web host that refers to the plot image in HTML source. All is well.
Problem: I would like to also display the plot locally from the Python program. I can do so with "set terminal X11", but every cycle thru the program spawns a new X11 plot window. gnuplot is called from python with: os.system('gnuplot -persist "/home/pi/pp/plotstuff.gnu"') After the plot is generated, gnuplot ends for that python program cycle, leaving the plot window persisting. But a new plot window is spawned every cycle.
How can tell gnuplot to plot to the already open X window, overwriting the previous plot in that window? I find references to "set terminal x11 5#5n6#6" but can't figure it out.
Upvotes: 0
Views: 516
Reputation: 12255
What you will have to do is replace your multiple gnuplot commands with a single gnuplot into which you pipe your data and commands from python. As an simple example, look how this bash script does what you want, creating files and updating a single window.
#!/bin/bash
f(){
let n=n+1
cat <<!
set title "plot $n"
set terminal gif medium size 1100,600 background "#e7e7ff"
set output "file$n.gif"
plot "-" with lines
1 $RANDOM
2 $RANDOM
3 $RANDOM
4 $RANDOM
end
set terminal x11
set size 1,1
refresh
!
}
while f
do sleep 5
done |
gnuplot -
Upvotes: 1