Search code examples
gnuplot

How to update numeric values on plot as plot changes


I'm trying to add time information on a plot of filled circles as they appear (one at a time) on the plot. So it looks like a movie of a filled circle moving around on the plot.

I've tried the simple Gnuplot code and dataset shown below. The problem is to get the updated time information from column one on the plot where the "?.???" is as the circle moves.

set terminal aqua 1
set size ratio -1
set style fill solid 
set ylabel "Y" 
set xlabel "X"
set label "Time=?.??? sec" at screen 0.7,0.8
do for [t=0:5] {plot [-.25:1.5] [-.25:1.5] "d.dat" every ::t::t u 1:2:(0.02) t "" w circles; pause 1.0}

and the dataset is:

# Time    x      y
 0.2000 0.0000 0.0000
 0.4000 0.2618 0.2588
 0.6000 0.5236 0.5000
 0.8000 0.7854 0.7071
 1.0000 1.0472 0.8660
 1.2000 1.3090 0.9659

I don't know how to work the time information from column one into the plot command.


Solution

  • You could use the plotting style with labels and plot the time from the datafile/datablock at a certain coordinate, here (0):(1.4).

    Code:

    ### time as label
    reset session
    
    $Data <<EOD
    # Time    x      y
     0.2000 0.0000 0.0000
     0.4000 0.2618 0.2588
     0.6000 0.5236 0.5000
     0.8000 0.7854 0.7071
     1.0000 1.0472 0.8660
     1.2000 1.3090 0.9659
    EOD
    
    set key left
    set xrange [-.25:1.5]
    set yrange [-.25:1.5]
    set style fill solid 
    
    do for [t=0:5] {
        plot $Data every ::t::t u 2:3:(0.02) w circles notitle, \
        '' u (0):(1.4):(sprintf("Time: %g",$1)) every ::t::t with labels notitle
        pause 1.0
    }
    ### end of code
    

    Result:

    enter image description here