I'm trying to show an animation using gnuplot
I got the following script:
plot ”heat1d.txt ” using 1:2 every :::a::a
pause 0.01
a=a+1
if ( a<b ) reread
that I execute using
a = 0
b = 100
load "a.plot"
it works, but is there a way to execute all of this using only 1 command from a shell?
Alternatively is there a way to integrate the variable definitions into the .plot file so that I can simply execute it? I tried different things like echo 'a=0'|gnuplot etc but it doesn't seem to actually define the variable correctly
thanks
You can use a do for loop.
do for [a = 0:100] {
plot ”heat1d.txt ” using 1:2 every :::a::a
pause 0.01
}
The default terminal on linux is usually wxt, and it has the raise option, which will change the focus to the plot window at every iteration. This will make it difficult if not impossible to stop the animation.
I suggest to put noraise as the terminal option. For example, you can put the following line at the beginning of the script:
set term wxt noraise
Now, if you want to stop the animation halfway, press CtrlC on the gnuplot terminal.
You can pass -e as a commandline argument. For example, if you have the script:
#script test.gp
print foo,bar
Then you could run it with gnuplot using:
gnuplot -e "foo=1;bar=2" test.gp
In your case, it looks like you could accomplish nearly what you want by invoking your script as:
gnuplot -e "a=0;b=100" a.plot
Related
I'm trying to make a bash script in combination with gnuplot.
I'm using an input file 'input.list' containing the single-column list of files to be analyzed with gnuplot.
I'm using a following bash script:
#!/bin/bash
while read -r line
do
...
#Other operations on files
...
gnupinp=$line
gnuplot -e "input='${gnupinp}'; plot input u 1:2; pause -1"
done < input.list
There are two issues probably connected:
When first file from the list is analyzed the plot is created but the pause -1 seems to be neglected while pause 1 works fine.
No matter if I use pause -1 or pause 1 the script fails starting from the #Other operations on files part when the second file from the list is executed.
The same behavior can be obtained when I use system 'sleep 1' command in gnuplot.
When I neglect pause command the gnuplot scripts are preformed properly for all listed files.
thanks in advance for any help
You are using the standard input in two competing ways: feeding the data to read, and to gnuplot's pause -1.
If you want the user to be able to interact with gnuplot by pressing return after the graph is plotted, you have to use some other way than stderr to feed your script with data, e.g. read from a file.
I have a Fortran 90 program that outputs some data to a .txt file.
The data is to be plotted with gnuplot.
I was able to launch gnuplot with
CALL SYSTEM("start wgnuplot")
which is equivalent to type
start gnuplot
in the Windows command line prompt.
But then, I would like to have the program telling gnuplot what to do next, i.e., changing directory to the right one, and plotting my file.txt.
All in all this boils down to a simpler question:
How do I pass a command line in Windows that launches gnuplot and gives it some additional commands?
I tried to do that with something even easier like plotting y=x.
In a normal gnuplot windows this is just plot x.
From the cmd.exe (which is what is called by Fortran's CALL SYSTEM() )I've tried:
start wgnuplot plot x
start wgnuplot plot x -pause
start wgnuplot plot x -persist
start wgnuplot plot x -noend
start wgnuplot plot x /noend
And others, including every possible variant with or without quotation marks, for instance
start wgnuplot "plot x -persist"
etc.
So far the only one that works is the basic
start gnuplot
Which starts gnuplot indeed. But then I don't know how to add the next commands. Once I have a working command line input I believe I will just have to plop it into the CALL SYSTEM argument to have my Fortran program doing all the work.
I could only find instructions on how to achieve this on a UNIX-like machine, but not on Windows.
Any help would be appreciated.
Background info: Windows 8, Code::Blocks, gnuplot 5.0 patchlevel 1
you need to use named pipes which are very easy in C and unix:
http://tldp.org/LDP/lpg/node11.html
and see this answer:
https://stackoverflow.com/a/14027358/2743307
in Fortran and UNIX you can use the shell mkfifo command:
https://genomeek.wordpress.com/2012/05/07/tips-reading-compressed-file-with-fortran-and-named-pipe/
I can't run my gnuplot script in background within a shell script. Something like in following example
#!/bin/bash
for i in 1 2 3
do
run gnu_script($i).p
done
As per the answer given by Christoph I could able to do it. But still the figure windows are coming and not letting me to do anything in the computer.
What about something simple as
for i in 1 2 3
do
gnuplot script$i.gp &
done
That assumes, that you have different scripts script1.gp, script2.gp and script3.gp.
If you have only a single script and want to pass the iteration number to it, you could do it with
for i in 1 2 3
do
gnuplot -e "i=${i}" script.gp &
done
A simple gnuplot script script.gp for testing this is
set terminal pngcairo
set output sprintf('script%d.png', i)
plot x title sprintf('%d', i)
pause 10
The pause 10 makes gnuplot pause for 10 seconds.
I have to plot a graph using gnuplot with the help of shell script.
I have written this code but its not working. I want to plot the graph in a html file so that I can see that graph in browser.
echo "set term canvas mousing size 500, 500
set output "file_name.html"
plot 'my_file.txt' with lines" | gnuplot
I have saved this file in .bash on the desktop.
Now I wrote this in terminal but it didn't work
sh file_name.bash
Please someone help me out with this. I am totally stuck with this thing since yesterday. :-(
There are multiple errors,
you use double-quotes within the echo which will not work. change it to single-quotes
use semi-colon instead of a line break for multiple gnuplot commands
So resulting script should be something like this
echo "set term canvas mousing size 500, 500; set output 'file_name.html'; plot 'my_file.txt' with lines" | gnuplot
or
cat << __EOF | gnuplot
set term canvas mousing size 500, 500
set output "file_name.html"
plot 'my_file.txt' with lines
__EOF
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
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.
You might be interested in the iteration capabilities available in newer versions of Gnuplot (see the section Iteration in the user's guide)
What about the following:
echo `for((i=1;i<6;i++))
do
echo 'plot sin(x)'
done` | gnuplot -persist
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.