automate gnuplot plotting with bash
If I understand correctly, this is what you want:
for FILE in *; do
gnuplot <<- EOF
set xlabel "Label"
set ylabel "Label2"
set title "Graph title"
set term png
set output "${FILE}.png"
plot "${FILE}" using 1:2:3:4 with errorbars
EOF
done
This assumes your files are all in the current directory. The above is a bash script that will generate your graphs. Personally, I usually write a gnuplot command file (call it, say, gnuplot_in
), using a script of some form, with the above commands for each file and plot it using gnuplot < gnuplot_in
.
To give you an example, in python:
#!/usr/bin/env python3
import glob
commands=open("gnuplot_in", 'w')
print("""set xlabel "Label"
set ylabel "Label2"
set term png""", file=commands)
for datafile in glob.iglob("Your_file_glob_pattern"):
# Here, you can tweak the output png file name.
print('set output "{output}.png"'.format( output=datafile ), file=commands )
print('plot "{file_name}" using 1:2:3:4 with errorbars title "Graph title"'.format( file_name = datafile ), file=commands)
commands.close()
where Your_file_glob_pattern
is something that describes the naming of your datafiles, be it *
or *dat
. Instead of the glob
module, you can use os
as well of course. Whatever generates a list of file names, really.