clear differentiation of throughputs in gnuplot - linux

I'm comparing the throughput of wireless link in two situations, i want to plot them both in a single graph. the problem is that the graph obtained by plotting throughput against time is as in this picture
when i plot both throughputs in the same graph i obtain something as in this second picture it is not clear to differentiate between the two.
I've used this code below for plotting a single throughput graph
#!/usr/bin/gnuplot
reset
!iperf -c 192.168.1.101 -i 0.5 -t 60 > a
#this is used for deleting first 6 lines
!sed -i 1,+5d a
#used to delete last line
!sed '$d' a > cropped
!cat cropped | cut -c 7-10 > b
!cat cropped | cut -c 35-38 > c
!paste b c > d
!awk 'BEGIN{print "0.0 0.0"}{print}' d > e
set xlabel "time"
set ylabel "throughput"
set terminal png nocrop enhanced font arial 8 size 900,300
#set terminal png size 900, 300
set output "chart_1.png"
#table name below graph(naming curve by colour)
set key below
plot 'e' using 1:2 title "Throughput Performance" with lines
below is the code which i have used for plotting both graphs
#!/usr/bin/gnuplot
reset
set xlabel "time"
set ylabel "throughput"
set terminal png nocrop enhanced font arial 8 size 900,300
#set terminal png size 900, 300
set output "chart_1.png"
#table name below graph(naming curve by colour)
set key below
set style data linespoints
plot "1" using 1:2 title "case1", \
"2" using 1:2 title "case2"
output looks like this:

As a general remark first: Use the pngcairo terminal which provides much better antialiasing.
For processing of your data you can use different smoothing options, like smooth csplines, smooth bezier or similar (see e.g. help smooth in the interactive gnuplot terminal):
plot "1" using 1:2 smooth csplines, "2" using 1:2 smooth csplines
Which smoothing variant you use depend again on the meaning of your data.
What could also help, is to use other point types then the default ones, e.g. pt 1 for the first and pt 7 for the second one, see Gnuplot line types for the use of the test command to check the available point types.

Related

error when trying to add gnuplot histogram labels

I am new to gnuplot, and I am trying to plot this data (gnuplot receives this input from stdin):
Regular 5
Block 3
Symbolic 8
Char 3
Socket 7
with this gnuplot code:
set style data histograms
set style fill solid
set terminal png
set output "plot.png"
plot '-' using 2:xtic(1), \
'' using 0:($2 + .1) with labels notitle
I get the error Not enough columns for this style. What am I doing wrong? If I remove the last line with labels, I am able to plot the histogram. How can I modify it to get data labels on top of each histogram bar?
Three columns of information x y text are needed for with labels. You gave coordinates but no actual text. Try
$DATA << EOD
Regular 5
Block 3
Symbolic 8
Char 3
Socket 7
EOD
set style data histograms
set style fill solid
set yrange [0:*]
plot $DATA using 2:xtic(1), \
'' using 0:($2 + .1):2 with labels notitle
Try this:
plot 'input_file' using 2, '' using 0:2:1 with labels offset 0, char 1
Note that I have added the values in a file named input_file and have set set yrange [0:10] to make the plot nicer to watch
This gives:

Is it possible to adjust the height of the boxes plot of gnuplot?

Following is the data.csv
#x,data
0,20
1,30
2,40
3,50
The following code uses gnuplot to plot the boxes plot and saves to png
import subprocess
proc = subprocess.Popen(['gnuplot','-p'],
shell=True,
stdin=subprocess.PIPE,
encoding='utf8'
)
proc.communicate(
f"""
set terminal png size 400,300; set output 'plot.png';
set boxwidth 1
set style fill solid 1.0
set xrange [-1:40]
set datafile separator comma
plot 'data.csv' using 1:2 with boxes notitle
"""
)
The output png image:
Is it possible to modify the height of each box and set it to 10?
Expected output:
Using this script adapted from Object placement using a data file, by the great Hagen Wierstorf.
reset
# The range has to be set manually
set xrange [-1:5]
set yrange [10:70]
set datafile separator comma
set style rectangle dashtype solid fc rgb "#0077ff" fillstyle solid noborder
# Rectangle dimensions
height = 10
width = 1
# --- Read placement from data file
# Set the output of the following plot to a table in order to achieve that it is
# not shown in the current terminal
set table '/dev/null'
# Function to create the right call function
add_rectangle(x,y,hgt,wdt) = sprintf(\
' set object rect from "%f", "%f" to "%f", "%f"; ',x,y,x+wdt,y+hgt)
# Initialize command string
CMD = ''
# Do a dummy plot to read the position data
plot 'data.csv' u 1:(CMD = CMD.add_rectangle($1,$2,height,width))
# Execute the drawing command
eval(CMD)
# Restore the terminal
unset table
# dummy empty plot to create the plot instance
plot x with line linecolor rgb"#ffffff" notitle
You can get this plot
As far has I know you can't circumvent setting the plot ranges manually, but since you are using a python script to invoke the plot maybe you can pass the min and max of the columns to the script and automate the setup.
By the way, there is the plotting style with boxxyerror, check help boxxyerror.
However, from your question and your sketch and your given data it is not fully clear whether you want
3 boxes; from one datapoint to the next (i.e. height = difference between two consecutive datapoints)
4 boxes; starting from the data value with fixed height 10.
Code: (second option)
### plot boxes with defined height
reset session
$Data <<EOD
#x,data
0,20
1,30
2,40
3,50
EOD
set xrange [-1:40]
set datafile separator comma
set style fill solid 1.0
plot $Data u 1:2:($1-0.5):($1+0.5):2:($2+10) w boxxyerror notitle
### end of code
Result:

Incorrect position and size of percentages in Gnu Plot

I have developped a CGI in bash/html that allow me to generate a graph of my clusters.
Here is an exemple :
This is a graph that works well. The problem is that for some graphs, the percentages overlap or shift far too far from where it should be. Here is my GNUPLOT code:
f(w) = (strlen(w) > 10 ? word(w, 1) . "\n" . word(w, 2) : w)
set title "TITLE"
set terminal png truecolor size 960, 720 background rgb "#eff1f0"
set output "/var/www/html/CLUSTER_NAME.png"
set bmargin at screen 0.1
set key top center
set grid
set style data histograms
set style fill solid 1.00 border -1
set boxwidth 0.7 relative
set yrange [*:*]
set format y "%g%%"
set datafile separator ","
plot 'test1.txt' using 2:xtic(f(stringcolumn(1))) title " CPU consumption (%) ", \
'' using 3 title " RAM consumption (%)", \
'' using 0:($2+1):(sprintf(" %g%%",$2)) with labels notitle, \
'' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle
Here is an example of a graph that does not work properly because the percentages are too shifted :
I am able to change this by changing this line in my code:
'' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle
To :
'' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle
Adding spaces allows to shift the percentages :
But even if it works for this graph, it moves the percentages for the other graphs too... :
I can't get "clean" graphics. Either the percentages overlap, or they go out of scope because the values are too large, or they are completely shifted....
Another example:
Is there a way to make all this move by itself, automatically, according to the values and therefore the size of the bars etc?
You might try an alternative mechanism, using plot for [i=2:3] ... to loop through the 2 columns of values. Instead of guessing the number of spaces to indent, you estimate the x position of the bar using column(0)+(i-2)*.25 (for i = 2 then 3),
which I got to by trial and error.
For example, using a function mytitle to get the 2 titles (my gnuplot is too old for an array):
mytitle(x) = (x==2?"cpu":"ram")
plot for [i=2:3] 'data' using i:xtic(stringcolumn(1)) title mytitle(i), \
for [i=2:3] '' using (column(0)+(i-2)*.25):(column(i)+1):\
(sprintf("%g%%",column(i))) with labels notitle

System time and Gnuplot

I am constructing a normal X/Y data plot using column data from a .txt data file. The graph plots well (see general code below).
I am wondering if it is possible to extract and use a System time in conjunction with the logged data in the .txt file?
This is in order to produce an X/Y plot with Y being the data from column [x] from the .txt file and the x-axis being an extracted system time point ??
The system time is not part of the log file.
The data string contained within the text file looks like this and is ; delimited: 221.5;65.9;-22.9;0;22.1
Code to generate the plot:
set multiplot layout 5,1
set title "Plot 1"
unset key
plot "data.txt" using 1 with linespoints ls 1
set title "Plot 2"
unset key
plot "data.txt" using 2 with linespoints ls 2
......
unset multiplot
In other words, for each data .txt file column point I would like to attach a system time giving as "Plot 1" {sys.time[x],221.5} and for "Plot 2" {sys.time[x],65.9}.
The next row of file data points delimited by ; will have another system time attached to each of them.
Thanks
I am still a bit guessing, but your image made it a bit more clear.
Maybe we can use this for further tweaking.
Some random data: data.txt
0.713;0.725;0.579;0.485;0.271
0.861;0.882;0.128;0.772;0.475
0.524;0.076;0.420;0.583;0.068
0.429;0.114;0.907;0.679;0.842
0.684;0.077;0.752;0.165;0.062
0.916;0.865;0.368;0.380;0.843
0.291;0.460;0.272;0.279;0.632
0.908;0.832;0.556;0.259;0.744
0.763;0.735;0.624;0.277;0.520
0.735;0.690;0.145;0.148;0.734
0.041;0.398;0.353;0.764;0.065
0.765;0.049;0.603;0.215;0.636
0.613;0.271;0.770;0.030;0.449
0.512;0.583;0.956;0.994;0.832
0.222;0.061;0.471;0.085;0.880
0.259;0.071;0.065;0.391;0.043
0.077;0.356;0.377;0.590;0.562
0.706;0.343;0.312;0.993;0.659
0.826;0.103;0.908;0.135;0.048
0.393;0.012;0.192;0.017;0.233
The code:
### adding time data afterwards
reset session
FILE = "data.txt"
set datafile separator ";"
set xdata time
set timefmt "%d.%m.%Y %H:%M"
set format x "%d.%m."
TimeIntervalInSeconds = 3600*24
StartTime = "01.01.2019 12:00"
set ytics 0.5
set multiplot layout 5,1
do for [i=1:5] {
set title sprintf("Plot %d",i)
plot FILE using (StartTime+$0*TimeIntervalInSeconds):i w lp lt i notitle
}
unset multiplot
### end of code
Result:

Unexpected output GNUPlot

I am drawing a simple graph using GNUPlot but output is not what I expected order.
Here is my script :
set title 'cost function vs clusters'
set xlabel '#clusters'
set ylabel 'cost function'
set terminal postscript
set output '| ps2pdf - output.pdf'
plot filename using 1:2 title "x" with linesp
Data on which I am plotting the data is :
13 0.004945370902817711
8 0.06739505462909719
2 0.28378378378378377
17 0.004657849338700402
5 0.015181138585393904
20 0.0018401380103507763
And here is my ouput :
I want points to be joined in sequential order of x.
How I can achieve this?
For the data you showed, you can use smooth unique. This sorts the data and replaces the same x-values with a single point having the averaged y value. If you can be sure, that you'll never have two equal x-values, then you can use this:
set title 'cost function vs clusters'
set xlabel '#clusters'
set ylabel 'cost function'
set terminal pdfcairo
set output 'output.pdf'
plot filename using 1:2 smooth unique title "x" with lp
And call it with gnuplot -e 'filename="aboveFile"' plot.gpi.
The other variant using sort also works fine:
plot '< sort -n '.filename using 1:2 title "x" with lp

Resources