Search code examples
gnuplot

GNUPLOT - Output Array of Stacked Images


at the bottom of this post is gnuplot sample code that plots an array of .dat files numbered 001 to 103 and turns them to an array of .png's. Below is the first and last image

enter image description here enter image description here

The question is, how do I stack the 001 to 103 .png's on top of each other and produce an output array of 103 images in the process? So far, I've managed to do one image that stacks all the combined data from 001 to 103.dat. See below

enter image description here

The bit of code that does the one stacked image is commented out

# Test.png - One merged data
#filename(n) = sprintf("ar-agn--DensT-%03.0f.dat", n)
#plot for [i=1:103] filename(i) using 1:2:3 with points pointtype 5 ps 0.3 palette notitle

But what I need is an array of output images stacked on top of each other.

Thank you all in advance!!!


#!/bin/bash

# Comment out the 3 lines below to produce all in one stacked image 
for FILE in ar-agn--DensT*.dat; do
gnuplot -p << EOF
set output "${FILE}.png"

set terminal png

# uncomment line below for all in one merged data
#set output "TEST.png" 

set datafile separator ","


set xlabel "x-units" font ",16"
set ylabel "y-units" font ",16"
set cblabel "y-units" font ",16"

set tics font ", 16"

set xzeroaxis 


#  Temp vs Density

set yr [0.0:8.0]
set xr [-3.0:6.0]

 set xlabel "log (Number density/(cm^{-3}) )"
 set ylabel "log (Temperature/ K )"

set cbrange [0.099949:10.2948]

set cblabel "Time (Myr)"

set palette  defined ( \
    0 '#0c0887' ,\
    1 '#4b03a1'   ,\
    2 '#7d03a8'   ,\
    3 '#a82296'    ,\
    4 '#cb4679'     ,\
    5 '#e56b5d'   ,\
    6 '#f89441'  ,\
    7 '#fdc328' ,\
    8 '#f0f921'  )

#  Series of subsequnt plots
plot  "${FILE}" u 1:2:3 with points pointtype 5 ps 0.3 palette notitle

# Test.png - One merged data
#filename(n) = sprintf("ar-agn--DensT-%03.0f.dat", n)
#plot for [i=1:103] filename(i) using 1:2:3 with points pointtype 5 ps 0.3 palette notitle


EOF

# insert comment into line below for all in one merged data
done


Solution

  • You were very close. You need two iterations, one inside the plot command and one outside:

    filename(n) = sprintf("ar-agn--DensT-%03.0f.dat", n)
    outfile(n) = sprintf("ar-agn--DensT-%03.0f.png", n)
    
    do for [N=1:103] {
        set output outfile(N) 
        plot for [i=1:N] filename(i) using 1:2:3 with points pointtype 5 ps 0.3 palette notitle
    }