How to plot and save many data files in GNUPLOT, inside a loop in a SHELL SCRIPT

Click For Summary
To efficiently plot and save multiple data files in GNUPLOT using a Shell script, a loop can be implemented. The script sets the terminal to JPEG format and iterates through the desired range of files. For each iteration, it formats the output filename and specifies the input data file for plotting. This method automates the process, allowing for the generation of numerous graphs without manual intervention. Utilizing this approach simplifies the task of handling large datasets in GNUPLOT.
alice06
Messages
6
Reaction score
0
Hi all
I badly need some help...

I plot a file output1.txt in the following way ::

Code:
gnuplot> plot "output1.txt" using 1:2 with lines, \
plot "output1.txt" using 1:3 with lines

BUT now I have many data files,

Code:
output1.txt, output2.txt, output3.txt, ...,... ,output1000.txt

I need to plot each one of them in gnuplot, and save them respectively in

Code:
graph1.jpeg, graph2.jpeg, graph3.jpeg, ..., graph1000.jpeg


It is very cumbersome if I plot and save 1 file at a time.

Is there an easy way, using loops in a Shell script that can PLOT and SAVE them

Please kindly help
Regards
Alice
 
Technology news on Phys.org
StackOverflow has some very good answers related to this:
https://stackoverflow.com/q/14946530/8387076You can write your code like this:
[CODE title="Gnuplot"]set terminal jpeg
do for [i=0:50] {
outfile = sprintf('graph%d.jpg',i)
set output outfile
plot 'output'.i.'.txt' using 1:2 with lines, 'output'.i.'.txt' using 1:3 with lines
}[/CODE]
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
3
Views
7K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K