Search code examples
animationlabelgnuplotparticles

Display a column value in label with gnuplot


I have a program that generates a file with the positions of particles in a box, and data contains also the pressure inside the box (every second let's say). With gnuplot I animate the particles in a loop but I want to display the pressure in a label. Is it possible ?

enter image description here

Here's the file. Pressure is in 4th column

enter image description here

My code :

# Titre du graphique
set title "Mouvement de particules d'Hélium (R = 3e-2 {/Helvetica=10 \305) \n sur une surface de      4 {/Helvetica=10 \305^{2}}"
set xlabel "L {/Helvetica=10 (\305)}"
set ylabel "L {/Helvetica=10 (\305)}"
set style line 2 lc rgb 'blue' pt 7 # cercle
set style fill solid 0.4
unset key
set size square
infile = 'particules.dat'
#stats infile using 1:2 name 'data' nooutput
k=21
do for [i=0:k] {
labels(x,y) = stringcolumn(3)
stats [*:*] infile using 5 name 'pression' nooutput
set label 1 sprintf("Pression : ", pression) at screen 0.2,0.9
plot infile index i using 1:2 with circles ls 2
pause 1.0
}

Solution

  • Not so elegant, but you can use multiplot. Using this as the core of your loop:

    set multiplot
    
    set size 1,1
    set origin 0,0
    
    set border
    set xtics; set ytics
    
    set xlabel "L {/Helvetica=10 (\305)}"
    set ylabel "L {/Helvetica=10 (\305)}"
    set title "Mouvement de particules d'Hélium (R = 3e-2 {/Helvetica=10 \305) \n sur une surface de      4 {/Helvetica=10 \305^{2}}"
    
    plot infile index i using 1:2 with circles ls 2
    
    set border 0
    unset xtics; unset ytics
    unset xlabel; unset ylabel
    unset title
    
    set origin -0.35,0.395
    plot infile index i u (0):(0):4 w labels
    
    unset multiplot
    

    MWE

    You may have to play with the current origin values.