Determine min and max in gnuplot

DCuser picture DCuser · Feb 20, 2013 · Viewed 25.6k times · Source

I am new to gnuplot and i am trying to determine the mina nd max from a datafile and afterwards plot the data

So far I have managed to determine the min and max like this:

# Define two helper functions
ismin(x) = (x<min)?min=x:0
ismax(x) = (x>max)?max=x:0

# Initialise the 'global' vars
max=-1e38
min=1e38

plot "Data.txt" u 0:(ismin($3)*ismax($3))

The problem is that I am trying to plot the data using splot, and it's not working.

I am trying this:

splot \
'Data.txt' u 2:1:3 with pm3d t '',\

If I remove the part related to determining the min and max, the splot command works.

Any suggestions?

Answer

andyras picture andyras · Feb 20, 2013

Look into the stats command:

stats 'datafile' using 3

for example, will get statistics on the 3rd column (z data), and store them in variables (STATS_min and STATS_max may be what you want). To see all the variables created, type

show variables all

after running stats. If you have an older version of gnuplot without stats, you can plot the file without creating an output, and gnuplot automatically defines some DATA_-prefixed variables including a min/max. The stats command saves the trouble of defining a null output to get data before plotting.