How to build single / multiple rows depending on values ​​in a column with GNUPlot

I have a little problem using gnuplot. Here is my data file:

From Time Packets Jitter  
127.0.0.1:53091 1 0 274  
127.0.0.1:53091 2 0 417  
127.0.0.1:53091 3 36 53  
127.0.0.1:53091 4 215 55  
127.0.0.1:53090 4 215 55  
127.0.0.1:53091 5 215 33  
127.0.0.1:53090 6 256 78

(I put this “time” for the test, but it will be replaced by datetime after it works)

I want to draw two different graphs: a column Timealong the x axis on both and a column Packets(on the first graph) and a jitter column (on the second graph) along the y axis. But, as you can see, I don’t know how many different values ​​from the column FromI will have (at least 1, but I don’t know the maximum, the data file will be updated, and some values ​​will be added every x seconds).
So my problem is that I want to draw another “line” for each other value Fromon both graphs.
In fact, having a value Fromin the row header (example: "127.0.0.1∗3091").
I want to add that if you can reorder the columns.

I tried:

plot 'data.log' using 3:xtic(2) title 'Packets' with lines, \
     'data.log' using 4:xtic(2) title 'Jitter' with lines

But this is on the same chart (I am not using multiplex yet, I tried to make a few lines before).

? , gnuplot?
, Jitter Packets , From.

+4
3

, , Linux bash. Lets , , .

1: 1: awk -f split.awk < data.log, split.awk:

#!/usr/bin/awk -f
# erase previous files
BEGIN { system("rm file_*.dat"); }

# print each line in a specific file
 { print $0 >>( "file_" $1 ".dat") }

2: ( gnuplot ):

for f in `ls file_*.dat`; do 
    head -n 1 $f > tmp.dat
    cat $f >> tmp.dat
    mv tmp.dat $f
done;

3: gnuplot script, plot, (. script ).

 echo "plot \\" >> plot.plt
 for f in `ls file_*.dat`; do 
     echo "   '$f' using 2:3 title columnheader(1) with linespoints lw 2, \\" >> plot.plt
done;
echo "    0 notitle" >> plot.plt

FIY, "0" , gnuplot . , . , ...

4: gnuplot script.

script : enter image description here

, , , .

script:

#!/bin/bash

# 1 - split data into one file per field 1
awk -f split.awk < data.log

# 2 - duplicate first line (useful for gnuplot)
for f in `ls file_*.dat`; do 
    head -n 1 $f > tmp.dat
    cat $f >> tmp.dat
    mv tmp.dat $f
done;

# 3 - generate gnuplot script
echo "set terminal pngcairo size 800,500" > plot.plt
echo "set output 'b.png'" >> plot.plt
echo "set multiplot layout 1,2" >> plot.plt

echo "set title 'Packets'" >> plot.plt
echo "plot \\" >> plot.plt
for f in `ls file_*.dat`; do 
    echo "   '$f' using 2:3 title columnheader(1) with linespoints lw 2, \\" >> plot.plt
done;
echo "    0 notitle" >> plot.plt

echo "set title 'Jitter'" >> plot.plt
echo "plot \\" >> plot.plt
for f in `ls file_*.dat`; do 
    echo "   '$f' using 2:4 title columnheader(1) with linespoints lw 2, \\" >> plot.plt
done;
echo "    0 notitle" >> plot.plt

echo "unset multiplot" >> plot.plt

# 4 - call gnuplot script
gnuplot plot.plt
+2

, . gnuplot:

filename = 'data.log'
from=system('tail -n +2 '.filename. '| cut -f 1 -d " " | sort | uniq')

awk gnuplot

select_source(w) = sprintf('< awk ''{if ($1 == "%s") print }'' %s', w, filename)

, from. gnuplot script :

filename = 'data.log'
from=system('tail -n +2 '.filename. '| cut -f 1 -d " " | sort | uniq')
select_source(w) = sprintf('< awk ''{if ($1 == "%s") print }'' %s', w, filename)

set style data linespoints
set multiplot layout 1,2

set title 'Packets'
plot for [f in from] select_source(f) using 2:3 title f

set title 'Jitter'
plot for [f in from] select_source(f) using 2:4 title f

unset multiplot

enter image description here

+3

, , , , How can I plot this two graphics in gnuplot ?:

set multiplot layout 1,2
plot 'data.log' using 3:xtic(2) title 'Packets' with lines
plot 'data.log' using 4:xtic(2) title 'Jitter' with lines
unset multiplot

:

enter image description here

0

Source: https://habr.com/ru/post/1545352/


All Articles