Need to plot every n'th row in gnuplot
-
05-12-2019 - |
Question
I am using gnuplot and have some data that have more than 2 parameters. I don't want to use 3D graphs. So I will split the data up in several lines in the same plot.
My data looks like this, in one case:
#k #N #time
1 1 0.000556134
2 1 0.00099
4 1 0.00201011
8 1 0.00376214
16 1 0.00675843
1 2 0.000717646
2 2 0.000794106
4 2 0.0016033
8 2 0.0033602
16 2 0.00795338
1 4 0.000476448
... ... ...
First is number of streams i use, second is buffer size and the last is time use on this opperation.
I want one graph where Buffer size is X, time Y and there is one line for every "amount of streams used". My code up to now:
reset
set autoscale # scale axes automatically
unset log # remove any log-scaling
unset label # remove any previous labels
set xtic auto # set xtics automatically
set ytic auto # set ytics automatically
#set logscale x 2
#set logscale y 2
set rmargin 10
set bmargin 5
set tmargin 5
set key left top
set title
set term png giant size 1500, 800 crop
set title "Adapter Stream Input" font "verdana, 20"
set xlabel "Buffer Size" font "verdana, 20"
set ylabel "Time in Seconds" font "verdana, 20"
set key right bottom spacing 4 width 5 height 5 font "verdana, 15"
set output "AdapterStreamInputTests.png"
plot "AdapterStreamInputTests.txt" using ($1 == 1 ? $2 : 1/0):($1 == 1 ? $3 : 1/0) title '1 Stream' with linespoints ls 1 linecolor rgb "blue", \
"AdapterStreamInputTests.txt" using ($1 == 2 ? $2 : 1/0):($1 == 2 ? $3 : 1/0) title '2 Stream' with linespoints ls 1 linecolor rgb "red", \
"AdapterStreamInputTests.txt" using ($1 == 4 ? $2 : 1/0):($1 == 4 ? $3 : 1/0) title '4 Stream' with linespoints ls 1 linecolor rgb "yellow", \
"AdapterStreamInputTests.txt" using ($1 == 8 ? $2 : 1/0):($1 == 8 ? $3 : 1/0) title '8 Stream' with linespoints ls 1 linecolor rgb "brown", \
"AdapterStreamInputTests.txt" using ($1 == 16 ? $2 : 1/0):($1 == 16 ? $3 : 1/0) title '16 Stream' with linespoints ls 1 linecolor rgb "pink"
set output
My main problem now is that it plots everything correct but it wont make lines between the plots. I read from the manual under the command "using" chapter that:
It should be noted that plot 'le', plot 'le' using 1:2, and plot 'le' using ($1):($2) can be subtly dierent: 1) if le has some lines with one column and some with two, the rst will invent x values when they are missing, the second will quietly ignore the lines with one column, and the third will store an undened value for lines with one point (so that in a plot with lines, no line joins points across the bad point); 2) if a line contains text at the rst column, the rst will abort the plot on an error, but the second and third should quietly skip the garbage.
I think I am in the third catagory and there is no lines because every plot have 4 invalid plots between them, but I cant find any way to fix it.
I can't find a way to make it ignore invalid plots. And there does not seem to be any way of preprocessing that I was able to find, that could remove the unused plots. But I am probably missing something.
Solution
Well there is two options for you.
1.) Use the every command as shown here, alternative link (wayback machine)
2.) Use the missing parameter, where you, as above use the ?: notation to prepend a character. More detail again on the great inofficial FAQ, alternative link (wayback machine)