Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
940 views
in Technique[技术] by (71.8m points)

bash - How do I make a plot in gnuplot with the lowest value automatically subtracted from the y data?

I am plotting the creation times of a large batch of files in gnuplot to see if they are created linearly in time (they are not).

Here is my code:

#!/bin/bash

stat -c %Y img2/*png > timedata

echo "set terminal postscript enhanced colour
set output 'file_creation_time.eps'
plot 'timedata'" | gnuplot

The problem I have is that the y data are the creation time in seconds since unix start time, so the plot just has 1.333...e+09 on the y-axis. I would like to have the creation time of the first file scaled to zero so that the relative creation times are readable.

I encounter this problem in a number of data-plotting contexts, so I would like to be able to do this within gnuplot rather than resorting to awk or some utility to preprocess the data.

I know the first time will be the smallest since the files are named serially, so is there a way to access the first element in a file, something like

`plot 'data' using ($1-$1[firstelement])`

?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you can do something like that...(the following is untested, but I think it should work...). Basically, you have to plot the file twice -- the first time through gnuplot picks up statistics about the dataset. The second time through, you use what you found on the first run-through to plot what you actually want.

set terminal unknown
plot 'datafile' using 1:2
set terminal post enh eps color
set output 'myfile.eps'
YMIN=GPVAL_Y_MIN
plot '' u 1:($2-YMIN)

If you have gnuplot 4.6, you can do the same thing with the stats command. http://www.gnuplot.info/demo/stats.html

EDIT It appears you want the first point to provide the offset (sorry, misread the question)...

If you want the first point to provide the offset, you may be able to do something like (again, untested -- requires gnuplot >= 4.3):

first=0;
offset=0;
func(x)=(offset=(first==0)?x:offset,first=1,x-offset)
plot 'datafile' using (func($1))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...