Gnuplot: Making gif animation file with 1500 data files - animation

I have a sequence of 1500 data files named like: 1.dat, 2.dat.....1500.dat, and I want to use gif terminal in gnuplot to make a gif file. I wrote a script to do this, which works pretty good if the number of the data file is not too large. When I tried to make a gif file using 1500 datafiles, the output is a broken file that can not be opened
I post my code as follow, the out.plt file is used to set up gif terminal and then load "loop.plt"; "loop.plt" is used to looping over all the data files:
#start of out.plt file
#This is used to load the loop file
#set up basis config
i=1
n=1500
set title "Suppressing Spiral Wave with Planar Wave"
set size ratio 1
set terminal gif animate delay 15 loop 1500
set output "control_spiral1.gif"
load "loop.plt"
set output
#end of out.plt file
and here is the loop.plt file:
#start of loop.plt
#This is the loop file to plot all data files
set pm3d map
set palette gray
splot sprintf("%d.dat",i) matrix
i=i+1
if(i<=n) reread
#end of loop.plt

Related

Problem with gnuplot in the construction of the histogram

everybody:
I'm having problems when it comes to representing the data in the form of a histogram.
I do not know very well how to clearly express what I intend, but my idea is:
3 groups of columns (carbides, borides and nitrides)
in each group of columns, 4 columns (hafnium, zirconium, titanium and
tantalum) each with a grid type.
So far, I have done what appears below, but it does not allow me to continue
My current code is:
reset
fontSpec(s) = sprintf("Times-Roman, %d", s)
set term post eps enhanced fontSpec(16)
set output 'TVsG.eps'
set grid
set auto y
set auto x
ticsFont=fontSpec(16)
set xtics font ticsFont
set ytics font ticsFont
set ylabel "Temperature" font fontSpec(25) offset char -1,0
set xlabel "Group" font fontSpec(25) offset 0,char -1
set style fill pattern border -1
set style data histograms
set boxwidth 1.0
set style histogram clustered gap 1
keyFont=fontSpec(18)
set key spacing 2 font keyFont
set key at graph 0.25, 0.9
fn(v) = sprintf("%.1f", v)
plot \
for [COL=2:4] 'data.txt' using COL:xticlabels(1) title columnheader fs
pattern 2, \
'data.txt' u ($0-1-1./6):2:(fn($2)) w labels font fontSpec(14) offset
char 0,0.5 t '' , \
'data.txt' u ($0-1-1./6):2:(fn($3)) w labels font fontSpec(14) offset
char 0,0.5 t '' , \
'data.txt' u ($0-1+1./6):3:(fn($4)) w labels font fontSpec(14) offset
char 0,0.5 t ''
and my data file
Material Hafnium Zirconium Titanium Tantalum
Carbide 3958 3400 3100 3768
Boride 3380 3245 3225 3040
Nitride 3385 2950 2950 2700
The main problem I have now is the following error:
gnuplot> load 'gnuplot2.txt'
"gnuplot2.txt" line 34: warning: Cannot find or open file "data"
"gnuplot2.txt" line 34: warning: Cannot find or open file "data"
"gnuplot2.txt" line 34: warning: Cannot find or open file "data"
"gnuplot2.txt" line 34: warning: Cannot find or open file "data"
"gnuplot2.txt" line 34: warning: Cannot find or open file "data"
"gnuplot2.txt" line 34: warning: Cannot find or open file "data"
"gnuplot2.txt" line 34: No data in plot
Now I'm at a point, I do not know how to continue
Gnuplot does not find the data file. I see two possible reasons:
The name of the datafile is wrong
The script has something like plot "data.txt", the error message mentions a file "data", note the missing .txt. => Check your script and the actual file name, it might be a simple typo or a missing file extension.
The data file is not in the directory where it is expected.
Add the command pwd (print working directory) as the first command in your script. It will print the directory where it expects the data file. If it is not the correct directory, you can:
move or copy your data file to this directory
use the cd command to change to correct directory
start gnuplot from the correct directory
use the plot command with the file name including path information
You use the load command and gnuplot seems to find the script. So I think most probably the data file should be in the same directory as the script gnuplot2.txt.
So far, this is the image that I have
Indeed, the problem was when selecting the directory in which the data was.
The problem now is that I do not know how I can change the format to give it a different color. Besides, I want to add the compound label on top of each column.
Any suggestions?

gnuplot unable to output image

I am trying to plot two column data. using first column as label of x axis (configuration) and and the seconds column as the value for the y axis(average_ mpki).
This is how my data looks like:
#assoc_valr blk_sz, cache_sz, rep_pol, avg_icache_mpki
4a128b32c1r 0.000682
4a128b32c2r 3.030329
4a128b16c1r 0.0333616
4a128b16c2r 0.0307207
4a64b32c1r 0.0125913
This is my ploting script:
# Gnuplot script file for plotting data in file "confs.out"
# This file is called confs.p
set style data histogram
set style fill solid border -1
filename="confs.out"
set boxwidth 0.15
set xlabel "Configurations"
set ylabel "Average MPKI"
set xtic rotate by -45 scale 0
set output "confs.png"
set terminal png size 1200,1200
plot "<(sed -n 'confs.out')" using 2:xtic(1) with histogram
I try plotting but it doesn't work, It doesn't throw any warning or error message but still it doesn't generate the output file for me. I can't see output when I try ploting without using the script also. I tried to gather windows to see if it is hidden under my terminal but it is not.
I also tried replacing the space separator with the tab in the data. Still not working.
gnuplot> load 'confs.p'
^C
gnuplot> plot 'confs.out' using 2:xtic(1) with hist
gnuplot> exit

Script Gnuplot on windows OS

I would like to automate the generation of graphs from a list of data files.
More details :
I have a directory that contain all my data files. I need to generate a graph for each of these files (hundreds). I have a gnuplot file to generate one graph but the name of the data file is specified into the gnuplot script.
For example :
plot 'myfile' index 1 using 1:2 with linespoints pointtype 2 linecolor rgb "green" title "leg"
I need to be able to replace "myfile" by a variable name that can be iterated on all the files of my directory.
You could have a (Windows) batch file with the following command:
for %%G in (*.dat) do gnuplot.exe -e "fn='%%G'" script
This will run gnuplot (and script) for every .dat file in the current directory.
The -e switch is used to input variables via command line (here the filename, surrounded by quotes in case it contains spaces).
If you want to run this command directly from the shell (as opposed to within a batch file), remove one of the % symbols from each of the two pairs.
Within the script file:
plot fn index 1 using 1:2 with linespoints pointtype 2 linecolor rgb "green" title "leg"
If the data files have a "normalized" name (e.g. data1.dat, data2.dat...) take a look at https://stackoverflow.com/a/14947085/3235496
In general you can iterate over many files inside gnuplot as follows:
set terminal pdfcairo
list = "fileA fileB fileC"
do for [file in list] {
set output file . '.pdf'
plot file
}
That kind of iterations requires at least version 4.6.0. In this example you have a fixed list of file names (these are not allowed to contain white spaces).
On Windows you could use
list = system('dir /b *.txt')
to get such a list containing all .txt files in the current directory. Note, that you must use wgnuplot_pipes.exe for this to work.
On a Unix system you could use
list = system('ls *.txt')

Animate multiple files with gnuplot

Say I have 'file1.asc', 'file2.asc' ... 'file 20.asc'. For each of these file, splot command in gnuplot represents an ellipsoid.
But I want to animate stacking all these files on a single plot and see these different ellipsoid.
I tried commands like:
do for [i=1:20] {splot 'data'.i.'.asc' using 4:5:6 with lines}
or
splot for [i=1:20] 'data'.i.'.asc' using 4:5:6 with lines
but none of them shows a continuos animation. I this command in a script "try". And the entered "gnuplot try" on command prompt. But no luck.
In order to get a rather smooth animation you must introduce a little delay between two plots with the pause command:
do for [i=0:10] { plot i*x title sprintf('%d', i); pause 0.5 }
In the same way, for your file you'll need
set style data lines
do for [i=1:20] { splot sprintf('data%d.dat', i) using 4:5:6; pause 0.5 }

Vbscript seek to end of file to make a tail command script

I've writen a simple tail command using vbscript. It works fine except for very large files where it has to read through the entire file to get the last 10 lines. Is there a way to seek to the end of the file and then read backwards for ten lines?
I am afraid that seeking backwards is impossible in VBS TextStream, but instead of reading through the entire file you can seek to a position eg. 1K before EOF and then read the rest of the file, displaying only the last 10 lines.
EDIT: I'm adding some sample code to illustrate the idea:
set fso = CreateObject("Scripting.FileSystemObject")
set file = fso.GetFile(filePath)
set stream = file.OpenAsTextStream(1, -2)
pos1KBeforeEnd = file.Size-1024
if pos1KBeforeEnd<0 then pos1KBeforeEnd=0
stream.Skip pos1KBeforeEnd

Resources