Plotting a Graph With Multiple Columns

Plotting a Graph With Multiple Columns

Post by Williams, James » Fri, 07 Dec 2001 00:35:52



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.

 
 
 

Plotting a Graph With Multiple Columns

Post by Hans-Bernhard Broeke » Fri, 07 Dec 2001 01:37:06



Quote:> 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.  

Gnuplot has no notion of "all" columns. You have to tell it which columns
you want plotted, explicitly.  This is done by the "using" option of
the "plot" command. More about this in

        help plot datafile
and     help using

You'll have to repeatedly plot the file, choosing a different column
to take the y values from each time.

--

Even if all the snow were burnt, ashes would remain.

 
 
 

Plotting a Graph With Multiple Columns

Post by Waya » Fri, 07 Dec 2001 01:42:51



> 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

you sould use the command plot "file" using col_4_x_axis:col_4_y_axis
if you want to plot more graph in a single plot, try the following way:

plot "file" using 1:2 with lines 1, \
     "" using 1:3 with lines 2, \
     "" using 1:4 with lines 3, \
     "" using 1:5 with lines 4

command "using" will tell gnuplot to plot what the columns will be
plotted. You do not need this command if your data is only 2 columns.
I don't exactly know how to plot date (I have never used it, sorry).

Wayan

 
 
 

Plotting a Graph With Multiple Columns

Post by crawfor » Fri, 07 Dec 2001 02:28:06



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 :-)


 
 
 

1. plotting data files with multiple columns

Hi,
I want to type in a command at the DOS promp (windows) like this:

wgnuplot.exe  filename1

filename1 is as follows:

# a comment
reset;
plot 'filename2'  with lines;
pause -1 "hit return to continue";

And, the file "filename2" will have at least three columns of data like
so..

0    1    32.3
1    7    45.07
2    8    30.0e6  etc., etc.

I cannot figure out how to plot the 2nd and 3rd columns vs. the first
one (first one is x-axis). I know that I have to add something to the
plot command, but what??

Any tips or help appreciated!

Thanks,
Paul

2. Newbie Question

3. Easier way to plot multiple timeseries columns?

4. PDF=pretty d**n frustrating. HELP!!!

5. Plotting multiple elements on one graph?

6. Full Screen bmp

7. Plotting Multiple Graphs w Different #'s of datapoints

8. 3D animations wanted

9. Multiple Graphs on Same Plot ?

10. Multiple plots on same graph

11. Plotting Multiple data sets on the same graph

12. Plotting multiple lines in a single graph

13. plot multiple graphs