1
votes

I have been working with using GNUplot to provide live changes in data in a .dat file using the reread function. The data is constantly changing in the xdirection like the time parameter. If I use set autoscale x the maximum x keeps on increasing to accomodate the changes. However, I do not want the scale of the graph to change and want the minimum x to move as well.

To summarize, is there a way we can have an xrange which would change over the interval like

if (x>5000) set xrange[(x-4000):(x+1000)]; else set autoscale x

I don't know how to have my last entry as x input.

To make this query more universal, a familiar problem that someone might come across. Plotting a sine curve over an infinite time series such that your plot is updated like an ECG.

1

1 Answers

0
votes

You could experiment with the stats command invoked before the actual plotting. In the example below, changes in the data file(s) are simulated by adding a uniform offset of 1000.

#use exists to initialize variables on first use
offset = exists("offset")?offset+1000:0
it = exists("it")?it+1:1

#sample data
$data <<EOD
1000 1
2000 2
3000 3
4000 4
6000 6
EOD

#enable autoscale so that stat processes the whole file on reread
set xr [*:*]
stat $data u ($1 + offset):2 nooutput

#adjust scale for the subsequent plot below
if(STATS_max_x > 5000){
    set xr [STATS_max_x-4000:STATS_max_x+1000];
}else{
    set xr [*:*]
}

plot $data u ($1 + offset):2 w l

if(it >= 10) exit

pause 1
reread