How to show median line on top of - gnuplot

I have a handy script that is running ab and generating plot afterwards. However there is a problem, it shows me every point (which is good), however I would like to see also the average "line" between them. I will show more in the picture.
So is there any way to add the median/medium ranger on top?
Script
#!/usr/local/bin/gnuplot
set terminal jpeg size 1280,720
set size 1, 1
set output OUTPUT
set title OUTPUT
set key left top
set grid y
set xdata time
set timefmt "%s"
set format x "%S"
set xlabel 'seconds'
set ylabel "response time (ms)"
set datafile separator '\t'
plot INPUT every ::2 using 2:5 title 'response time' with points
exit
Ouptut
Output (what I would like to have)

That can be done with the smooth unique option:
This makes the data monotonic in x; points with the same x-value are replaced by
a single point having the average y-value. The resulting points are then connected by straight line segments.
plot INPUT every ::2 using 2:5 title 'response time' with points,\
'' every ::2 using 2:5 smooth unique title 'average' with lines

Related

Gnuplot-- adding too much data to xaxis

I've got a file that is "date,time,temperature" new line "date,time,temperature" etc
Example:
12/01/19,23:30:13,74.23
12/01/19,23:45:13,74.33
12/02/19,00:00:13,74.20
12/02/19,00:15:13,74.06
And am looking to Graph it using Gnuplot.
The graphing portion comes out just fine, and for the most part it looks like it will do the trick for what i need.
However, the xtics are adding additional information that i did not set for them to have and have no idea where it's coming from.
Code:
set terminal gif animate delay 200
set output "path/to/file.gif"
set datafile separator ","
set title 'Temperature in Aquarium"
set key bottom left box
set key width 1
stats "path/to/file.csv" using 2:3 name "A"
set xlabel 'Time'
set xdata time
set timefmt '%H:%M'
set xtics 14400
set ylabel 'Temp(F)'
set yrange [68:80]
set style data lines
do for [i=0:int(A_blocks-1)] { plot 'path/to/file.csv' using 2:3 index i title "Dec " .(i+1)
What i'm expecting to see in the x-axis is simply "00:00, 04:00, 08:00, 12:00, 16:00, 20:00, 00:00"
And i do see that for any data gathered from Today.
but any data that is gathered from a previous day looks like:
"01/01 00:00, 01/01/ 04:00, 01/01 08:00, 01/01 12:00"...
And each day after repeats that for the x-axis, until it gets to Todays data and then it shows me the "00:00, 04:00, 08:00..."
So how can I get it so it doesn't show me the "01/01" on all previous days?
Completely revised code.
I guess you haven't set the format for the x axis, e.g. set format x "%H:%M".
I thought set xdata time is somewhat "outdated", instead use set format x "%H:%M" timedate and as you might know, time is handled as seconds from 01/01/1970.
Here a possible starting point for further tweaking.
Code:
### animated time data
reset session
set term gif size 480,320 animate delay 100
set output "Animation.gif"
set datafile separator ","
myTimeFmt = '%m/%d/%y,%H:%M:%S'
# generate some test data
StartDateTime = strptime(myTimeFmt, "12/18/19,00:00:00")
set print $Data
do for [day=0:7] {
do for [i=0:24*4-1] {
print strftime(myTimeFmt,StartDateTime+day*24*3600 + i*15*60). \
",".sprintf("%.1f",74+6*sin(i/12.)+rand(0)*3)
}
if (day<7) { print ""; print ""} # 2 empty lines at the end of the day
}
set print
set timefmt myTimeFmt
set format x "%H:%M" timedate
set xtics 4*3600
stats $Data u 0 nooutput
set key top center
do for [i=0:STATS_blocks-1] {
plot $Data u (timecolumn(1,myTimeFmt)):3 index i w lp pt 7 ti strftime("%b %d", StartDateTime+i*24*3600)
}
set output
### end of code
Result:

Plot error_bars with lines in gnuplot

I have a file with the delivery rate of a simulation and its confidence interval. I need to plot an error bar on my chart. Need to be the line graph and also the error bar on a single chart
Sample data:
V D IC
10 99.2373 0.000200729
30 97.2515 0.00649952
60 94.6761 0.00950475
I would like it to look like the example below:
Here is my code:
set nokey
set grid
set key right inside
set xlabel 'Velocidade em Km/h'
set ylabel 'Taxa de Entrega'
set autoscale
set yr[0:100]
set style data lines
plot 'taxa_entrega-AODV-50-250.txt' using 1:2:($2-$3):($2+$3) with yerrorbars
if you are plotting errorbars you typically plot data with points but not necessarily with connected lines or linespoints. Instead you add a line described by a model or fit.
However, from the image you are referring to I assume you want to have the points nevertheless connected. So, simply add ,\ the same data '' again as lines.
plot 'taxa_entrega-AODV-50-250.txt' using 1:2:($2-$3):($2+$3) with yerrorbars,\
'' using 1:2 with lines
Addition: See below what you get with the full code. (I commented out the set yrange[0:100] because otherwise one wouldn't see too much with the data you provided. Furthermore, your errobars are in the range of 0.0002 to 0.009. Relative to the values 94.6 to 99.2, these will not be bars but more points.
reset session
set nokey
set grid
set key right inside
set xlabel 'Velocidade em Km/h'
set ylabel 'Taxa de Entrega'
set autoscale
# set yrange[0:100]
set style data lines
plot 'taxa_entrega-AODV-50-250.txt' using 1:2:($2-$3):($2+$3) with yerrorbars,\
'' using 1:2 with lines

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

Junk in the terminal when trying to export .png

I have a file (called print_1012720.txt) that looks like the text shown below.
1133254688 5698771509078629376
1150031904 5698771509371165696
1150031904 5698771510035551232
4170258464 5698771510036082688
2895583264 5698771510036715520
1620908064 5698771510037202176
346232864 5698771510037665280 <----
3366459424 5698771510038193664
2091784224 5698771510332259072
817109024 5698771510332816128 <-----
3837335584 5698771510333344512
2562660384 5698771510339882240
1287985184 5698771510340411392
13309984 5698771510340939776 <-------
3033536544 5698771510348048896
1758861344 5698771510348577280
484186144 5698771510349228800
3504412704 5698771510632804864
2229737504 5698771510633441792
955062304 5698771510634390272
3975288864 5698771510638858496
2700613664 5698771510639347712
1425938464 5698771510642663168
134486304 5698771510643387136
3154712864 5698771510643808768
I am running the following commands in bash.
gnuplot
reset
set terminal png
set xdata time
set timefmt "%d/%m/%Y %H:%M:%S"
set format x "%H:%M"
set xlabel "time"
set ylabel "highest seq number"
set yrange [0:65535]
set title "seq number over time"
set key reverse Left outside
set grid
set style data linespoints
plot "print_1012720" using 1:2 title "Flow 1"
It gives garbage in my shell. I suspect that it is the spacing between the columns that is causing this. However if I correct the spacing then the file is correctly plotted. Any clue how this can be rectified?
I suspect your main problem is that you are not setting an output. After your set terminal command you should set an output file, otherwise gnuplot will spit out the .png to your terminal, which looks like gibberish. Try putting the following in a file (saved as 'plot.plt' for instance) and then run gnuplot plot.plt at the bash command line.
set terminal png
set output 'output.png'
set xdata time
set timefmt "%s"
set format x "%H:%M"
set xlabel "time"
set ylabel "highest seq number"
set title "seq number over time"
set key reverse Left outside
set grid
set style data linespoints
plot "print_1012720.txt" using 1:2 title "Flow 1"
Creating a plot file this way will save you a lot of time typing at the gnuplot command line.
A couple of other comments:
1) You set your yrange to be 0:65535 when your y values from the datafile are much larger.
2) It looks like you are trying to extract a time in UNIX format from the first column in your datafile. For this you would want the line set timefmt '%s' as I have above. However, the time data in the data file appear to be all over the place, as do the y data.
3) You do not need the reset command at the beginning, since running gnuplot this way will create a new instance of gnuplot, so there will be nothing to reset.
4) You also had 'print_1012720' without the '.txt' extension; I'm not sure this was an error on your part.

Resources