Praveen Chandrashekar

Centre for Applicable Mathematics, TIFR, Bangalore

[ People | News | Codes | Talks | Teaching | Publications | Calendar | Hiking | Contact ]

Gnuplot tips

Simple animation

This example shows how to directly pipe data to gnuplot to get an animation.

      program main
      implicit none

      integer it, i, np
      real*8  t, dt, dx, x, PI

      dt = 0.1d0
      t  = 0.0d0
      np = 100
      dx = 1.0d0/(np-1)

      do it=1,100
         t = t + dt
         print*,"set title 'Iter=",it,"  Time =",t,"'"
         print*,"set xlabel 'x'"
         print*,"set ylabel 'f'"
         print*,"plot [0:1][-1.1:1.1] '-' w l lw 2"
         do i=1,np
            x = (i-1)*dx - t
         print*,"pause 0.2"


Compile the fortran program and run it as follows

gfortran anim.f
./a.out | gnuplot

Animate solution from files

Plot by naming files

set style data lines
do for [i=0:6] { plot sprintf('sol-%04d.gnu', i) using 1:2; pause 0.5 }

Plot automatically all files which match some pattern

set style data lines
do for [f in system("ls sol-*.gnu")] { 
    plot f using 1:2
    pause 0.5