how to save two plots simultaneously in gnuplot - 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.

Related

Script to launch gnuplot and plot graph

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.

Separate file plots from different data files gnuplot

I have 3000 .dat files which I want to plot using gnuplot.
They are all named as "iteration_1", ...", iteration_93", ..."iteration_1247",... (not in the format "iteration_XXXX", if this information is helpful).
Each of those files is to be plotted in an .eps file - my final intention is to do a video (an evolution of those plots), which I can easily make if I have the .eps files.
Is there any way to quickly command gnuplot to do this? All the questions I have found remotely similar to my situation were all actually regarding putting data from different files into one plot in a single file.
Again, I do not want to put all the plots into a single .eps file. I want 3000 .eps files.
Thanks in advance!
Simply put your plotting routine in a do for loop. By the way, gnuplot can also do animated GIFs. Check help gif.
### create output files in a loop
reset session
set terminal epscairo
do for [i=1:3000] {
FILE = sprintf("iteration_%d",i)
set output FILE.".eps"
plot FILE.".dat" u 1:2 w l # or change your extension and plot command accordingly
}
set output
### end of code

Gnuplot shell script ROS data from multiple files

I'm trying to plot data from two different rosbag files using gnuplot. I'm trying to automate this as I have quite a few files that will need to be run.
I need to take the first element of the first column of each file and offset the data of the column w.r.t. that (and then divide by 10^9) to get the time in seconds. My issue is my script returns something different when I run it multiple times. It will either return the first, the second, or (occasionally) the third plot command, which is what I'm interested in.
The code I've cobbled together is below:
#!/bin/bash
gnuplot -persist <<-EOFMarker
set autoscale
set datafile separator ","
set key autotitle columnhead
plot "bag1" using (\$1):2 with linespoints
first=GPVAL_DATA_X_MIN
plot "bag2" using (\$1):3 with linespoints
second=GPVAL_DATA_X_MIN
plot "bag1" using ((\$1-first)/10**9):2, "bag2" using ((\$1-second)/10**9):3
EOFMarker
An example of the dataset is:
%time,field.1,field.2,field.3
1.50317427276591E+018,23,64,64
1.50317427281556E+018,232,74,64
1.50317427285689E+018,216,76,64
1.50317427287325E+018,183,85,64
1.50317427292519E+018,165,89,64
1.50317427298662E+018,129,96,64
1.50317427300161E+018,115,101,64
1.50317427309547E+018,102,112,64
And the second input file is:
%time,field.1,field.2,field.3,field.4
1.50317425501603E+018,55,45,229,98755
1.50317425501843E+018,55,45,229,98752
1.5031742550235E+018,51,43,229,98758
1.50317425502979E+018,51,43,229,98761
1.50317425504176E+018,55,41,231,98764
1.50317425504579E+018,55,41,231,98770
1.50317425504728E+018,50,42,232,98773
1.50317425504855E+018,50,42,232,98773
1.50317425505353E+018,55,41,229,98770
1.50317425506442E+018,55,41,229,98770
I've never experienced code where multiple runs produces different results. Can anyone point me in the right direction to fix this mess?
The outputs are the three plots below. No error message is output from the script at any time.
First output:
Third (and desired) output:
I don't know why you are sometimes getting different results; I always get the output of the last plot command. However, you seem to be using the first two plot commands only to get the minimum value of the first column for each of the two files. A better way that doesn't generate any plots would be
set datafile separator ","
set key autotitle columnhead
stats "bag1" using 1
first=STATS_min
stats "bag2" using 1
second=STATS_min
plot "bag1" using (($1-first)/10**9):2, "bag2" using (($1-second)/10**9):3

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.

Resources