2
votes

I want to plot different lines in a single image. Each line is saved in a different plain text file and it has: x | y | depth. Therefore, I have write this file named 'plot_vg':

set term pngcairo size 1000,8005

list = system('ls')
i = 1

set output 'image.png'

do for [file in list] {
if (file ne 'image.png') {
   if (file ne 'plot_vg') {
       if (file ne '..') {
         if (i==1) {
           i=0
           plot sprintf('%s',file) using 1:2:3 with lines notitle
         } else{
           replot sprintf('%s',file) using 1:2:3 with lines notitle
         }
       }
    }
}
}

My problem is that at the end, the saved image is only of the last replot without including the rest of lines. I have seen that it's entering well to the loop and it does 1 plot and then, the rest are replots. If I open gnuplot from term and I write first 1 plot and then replots, the image shown is what I want. Where's the error here?

I tried the first option from here Gnuplot - Using replot with png terminal but I'm getting a blank image file.

1

1 Answers

1
votes

Do the filtering already when you read the file list, and then iterate with plot for [file in list]...:

set term pngcairo size 1000,8005

list = system("ls | grep -v 'image.png\|plot_vg'")

set output 'image.png'

set style data lines
unset key
plot for [file in list] file using 1:2

If your data files follow some pattern you could also use something like

list = system("ls *.txt")

Note also, that a simple plot with lines uses only two columns.