Script to launch gnuplot and plot graph - gnuplot

I am trying to launch gnuplot and plot the graph for me with a single command. My script looks like this:
gnuplot
load "runscript"
But it would ignore the second command. Any help would be appreciated,Thanks.

I think that is no necessary to create another script to launch Gnuplot and then load your plotting script. This task is easy to be done using the Gnuplot commands. For example, consider you have a script called "test.gp" and its contents are:
set xlabel "Time t"
set ylabel "sin(t)"
set title 'Gnuplot test with PDFcairo'
plot [0:2*pi] sin(x) with lines lw 2 title 'Sin(x)'
Then, to run your "tes.gp" script just go to the folder that contains the file, and type in the command line:
gnuplot -p test.gp
the '-p' option allows the persist mode and remains the plot window.

Related

how to save two plots simultaneously in gnuplot

Hiii...
I havebeen trying to plot two curves simultaneously in a single plot to compare them. ie, by the command:
plot "1.txt" w l, "2.txt" w l
now I want to save it, but the usual command for saving is:
set out "1.txt"
but in this case how can I save them together in a same plot?
For saving a plot as a file on your disk, you need to setup two things: a terminal and an output. Suppose you have configured your plot interactively in a command-line gnuplot session, this is an example:
set terminal png
set output "myplot.png"
replot
unset output
where replot does what its command name suggests, it repeats the last plot command - and if that last plot command showed both curves as you wanted it, they will identically show up in the output file. For info on supported terminal types on your system, read help terminal.

GNUPLOT cannot zoom in

I am having an issue where I am unable to zoom in on my GNUPLOT. I created a bash script that records various resource information, and displays this information via the following command.
gnuplot -e persist "set title 'Resource monitor' ; set timefmt '%y/%m/%d-%H:%M:%S' ; set xdata time ; set xlabel 'TIME' ; set ylabel 'PERCENT' set yrange [0:101]" -e "plot '${cpuResFile}' using 1:2 title 'CPU' smooth Bezier, '${memResFile}' using 1:2 title 'MEM' smooth Bezier" &
The graph is viewable and displays my information I want, I just cannot figure out how to allow it to zoom in and out. I read that it has something to do with the X11 window no longer being set or that I need to set it via the command line, I just cannot figure out exactly how to, or if this is even the reason. Hopefully there are a couple GNUPLOT experts that can assist me. :)
Thank you.
Zooming and unzooming isn't possible in interactive windows which are left open with the -persist flag. Those operations would require a redrawing which isn't possible anymore since the main programs has already exited.
Quoting from the persist documentation:
[...] gnuplot will open a display window, draw the plot into it, and then exit, leaving the display window containing
the plot on the screen. Depending on the terminal type, some mousing operations may still be possible in
the persistent window. However operations like zoom/unzoom that require redrawing the plot are generally
not possible because the main program has already exited
You could add pause -1 at the end of the command list:
gnuplot -e "plot sin(x); pause -1" &

Two interactive windows in Gnuplot with wxt terminal

I often use the wxt terminal of Gnuplot to do some quick data inspection. I like the interactivity, such that I can easily gain control and zoom/move et cetera.
Suppose I have to following script
set terminal wxt 0 persist
plot x
set terminal wxt 1 persist
plot x**2
Now, on window 1 I have the interactive control. However, on window 0 this interactive control is lost.
My question is: How can I obtain interactive control on window 0?
I am using gnuplot 4.6.2. I've seen gnuplot multiple graphs are not interactive but the question in about x11 terminal, and the answers consist of opening multiple instance of gnuplot, which seems unnecessary to me.
I believe have found a workaround for this problem.
But not sure if this works for all cases.
My solution sounds like obvious.
I created three files: configs.plt, wxt1.plt, and wxt2.plt.
The configs.plt file contains:
set style line 1 lc "#e41a1c"
set style line 2 lc "#377eb8"
The wxt1.plt file contains:
set terminal wxt title "plot sin"
load "configs.plt"
plot sin(x) w l ls 1
The wxt2.plt file contains:
set terminal wxt title "plot cos"
load "configs.plt"
plot cos(x) w l ls 2
The only boring thing is run two instead one file.

Gnuplot nested do loop and plotting on the same graph

Hi I'm using gnuplot to create a large number of graphs. To save myself work I've written a script that tries to plot all possible graphs.
#!/usr/bin/gnuplot
reset
is_missing(x)=system("./ismissing.sh ".x)
set terminal post eps enhanced color
set key inside right top vertical Right noreverse enhanced autotitles box linetype -1 linewidth 1.000
set grid
models="Cebeci-Smith Baldwin-Lomax Spalart-Allmaras Launder-Sharma Chien"
files="./CebeciOut/ ./BaldwinOut/ ./SpalartOut/ ./LaunderOut/ ./ChienOut/"
xgrid="35000 70000 140000 280000 560000"
# Plot grid convergence Spalart
do for [f=1:words(files)]{
set output sprintf('%s%s',word(files,f),'ZPGGridConvergence.eps')
set title sprintf("%s%s",word(models,f), " ZPG Grid Convergence")
set xlabel "N_y"
set ylabel "C_f Final"
print f
do for [i=1:words(xgrid)]{
filename=sprintf("%s%s%s%s",word(files,f),'yconv_',word(xgrid,i),"x")
if(is_missing(filename)==0){
plot filename using 1:2 title sprintf("%s%s",word(xgrid,i), " X Gridpoints") with linespoints
}
}
}
Unfortunately I have a problem, after one full iteration the script fails, ie f is never made 2 despite the first plots completing successfully. The error given is
cannot open file; output not changed
line 25: util.c: No such file or directory
which I haven't managed to decipher. Any help would be much appreciated. Also is there a way to use replot in this loop given I haven't already created a plot.
Thanks
"files" are actually dirs in your code.
If you want to place the output in a subdir, then make sure that it exists and is writable.
gnuplot cannot create subdirs automatically. You can add system("mkdir -p ".word(files,f)) ( on linux/unix) in your code to create the directory if needed.

Keep Gnuplot auto refresh window inactive

I am running a simple script, that reads data from a file and plots it. My problem is that I reread and replot the data, as the file continuously changes. Whenever I use refresh the plot window becomes active again, which I would like to prevent. I would like the plot to be updated in the background. Is this possible?
My sample script:
#!/usr/bin/gnuplot
set datafile separator ","
plot "data.dat" using 1:3
pause 1; refresh; reread;
This depends on what terminal you're using. wxt, x11 and qt support a noraise option:
set term x11 1 noraise
This should allow it to stay in the background.

Resources