Quote:> I am using version 3.7 of gnuplot on a Sun server running Solaris 8. I am
> trying to create a plot that would include all columns from a datafile
> similar to this:
> 01:00:00 2 1 0 97
> 02:00:00 1 1 0 98
> 03:00:00 1 1 0 99
> 04:00:00 1 1 0 99
> 05:00:00 2 1 0 97
> 06:00:00 1 1 0 99
> 07:00:01 1 1 0 98
> 08:00:00 2 1 0 97
> 09:00:00 6 1 0 93
> so that the finished graph would have four lines (columns 2 through 5). I
> inherited a system that was designed to only print the last column; I need
> to modify it so all columns are plotted. I've looked through the
> documentation and the answer seems to lie in the "ranges" area but I can't
> quite figure it out.
> My existing plot command looks like this:
> plot [0:23] [0:130] "/servstats/internet/cpu/cpufile2" title "%CPU Idle
> Time" with lines lt 9, 80 title "Acceptable %Idle Time" with lines lt 1
> Any help would be greatly appreciated.
The old format presumably had just two columns -- one with the hour, the
other with the CPU Idle Time percentage.
The "plot" command has a "using" option which lets you choose which columns
of a multi-column file are to be assigned to x and y. Details can be found
in "help plot using". In short, you can duplicate the picture made from the
old data format with data in the new format by using the command
plot [0:23] [0:130] "/servstats/internet/cpu/cpufile2" using 1:5
title "%CPU Idle Time" with lines lt 9,
80 title "Acceptable %Idle Time" with lines lt 1
(As you modify the "plot" command, it may get long enough that you want to
break it into two or more lines. The backslash is the continuation
character. It must be the final character on the line -- not even a space
can follow it.)
The above syntax already shows how to draw two lines on the plot -- the one
consisting of the data in column 5 and the other being at a constant value
of 80 -- by separating the options for each with a comma. So, for example,
column 3 can be added to the plot by changing the command to
plot [0:23] [0:130] "/servstats/internet/cpu/cpufile2" using 1:5
title "%CPU Idle Time" with lines lt 9,
"" using 1:3 title "Whatever is in column 3" with lines lt 6,
80 title "Acceptable %Idle Time" with lines lt 1
I have used the convention that an empty file field means that the
previously referenced file will be reused.
I'll mention two more features of gnuplot that you may want to investigate.
One is date/time data, since your x-values are times.
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M"
plot "filename" using 1:5
would read the first column as hours:minutes:seconds (that's what the
"timefmt" specifies) and label the x-axis as hours:minutes (that's what "set
format x" specifies). (Again, the on-line "help" for these commands gives
all the grubby details.)
As long as your data points are at integral numbers of hours, they will be
plotted correctly with or without this feature invoked. But if your times
are not integral hours, you'll need this -- otherwise 5:30 will be plotted
30% of the way between 5:00 and 6:00 instead of halfway between them.
The second feature is multi-axis plotting. Since the numbers in columns 2
through 4 are a lot smaller than the numbers in column 5, if you plot them
all against a single axis, you'll have one line at the top of the plot and
the rest plotted virtually on top of the x-axis. You might want to plot
columns 2--4 against the right-hand axis, which gnuplot lets you define
independently of the left-hand axis. All of the commands that refer to the
(left-hand) y-axis have twins for the right-hand ("y2") axis -- "set yrange"
and "set y2range", "set ytics" and "set y2tics" and so forth. Similarly
those commands (like "set format", discussed above) which accept the axis as
an option accept both "y" and "y2". Thus the commands might look like
set yrange [0:130]
set y2range [0:10]
set ytics nomirror
set y2tics
plot [0:23] "/servstats/internet/cpu/cpufile2" using 1:5
title "%CPU Idle Time" with lines lt 9,
"" using 1:3 axes x1y2 title "Whatever is in column 3" with lines lt
6,
80 title "Acceptable %Idle Time" with lines lt 1
Note that I moved the y-range off of the "plot" command to its own "set
yrange" command -- I think it's more obvious what's going on when done this
way (just a matter of personal style). (I'll let you look up the other
options, like "set ytics nomirror", in the on-line "help".)
Please forgive me if I've gotten carried away -- I hope I haven't wandered
too far afield from your question :-)