1

I need to plot a couple of curves in a single window. Using for loop in bash shell I've been able to plot them on separate files , but no success in sketching them on a single pic. I would appreciate it if you can guide me on how to resolve this issue.

I tried to implement the example in thie link for loop inside gnuplot? but it gives me an error saying: ':' expected .I have gnuplot 4.2 installed. Thanks,

#!/bin/bash

for Counter in {1..9}; do
FILE="dataFile"$Counter".data"
    gnuplot <<EOF
    set xlabel "k"
    set ylabel "p(k)"
    set term png
    set output "${FILE}.png"
plot [1:50] '${FILE}'
EOF
done
Community
  • 1
  • 1
PyPhys
  • 129
  • 5
  • 10

1 Answers1

1

Looping inside the plot command works only since version 4.4 and would look like

file(n) = sprintf("dataFile%d.data", n)
plot for [i=1:9] file(i)

Using bash I would construct the plot command inside the bash loop and use this later in the gnuplot script:

for Counter in {1..9}; do
  FILE="dataFile${Counter}.data"
  if [ $Counter = 1 ]; then
    plot="plot '$FILE'"
  else
    plot=$plot", '$FILE'"
  fi
done
gnuplot <<EOF
set xlabel "k"
set ylabel "p(k)"
set term png
set output "output.png"
$plot
EOF
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Thanks for the respond. Your solution works, however, my problem still exits since I have posted a simplified version. For each curve I also would like to fit an exponential curve to each set of data as well. Again I've been able to do it in my shell resulting in several output files. Any chance, you would know of a way to plot for each set both the curve and a fit curve? – PyPhys Oct 03 '14 at 00:29
  • By the way if you think this deserves a new thread pleas let me know, I will ask this as a new question. – PyPhys Oct 03 '14 at 00:30