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:
Related
For this datafile:
Server ID,Sponsor,Server Name,Timestamp,Distance,Ping,Download,Upload,Share,IP Address
4981,SELCO,"Shrewsbury, MA",2022-01-19T17:45:00.941297Z,46.02761207264913,16.34,202120227.4774976,5410786.336552021,,66.30.193.6
27031,BELD Broadband,"Braintree, MA",2022-01-19T18:45:01.962140Z,26.98449241976281,17.566,140849719.78516415,5441730.586693773,,66.30.193.6
27031,BELD Broadband,"Braintree, MA",2022-01-19T19:15:01.589345Z,26.98449241976281,17.419,156811809.4210379,5371285.306441804,,66.30.193.6
38849,FiberCast,"Stoddard, NH",2022-01-19T19:45:00.746522Z,106.41034005246897,20.042,215161640.72859222,6086086.612413734,,66.30.193.6
I would like a plot with column 7 on the y-axis and column 4 on the x-axis. I would like to make the x-axis go from Jan 21-2022 to Jan-25 2022. I would like the y-axis to be scaled so that 1 is 10^6.
The problems have to do (I think) with the parsing of the date.time and the scaling of the x axis.
set datafile separator ","
set key autotitle columnhead
set terminal pdf
set output "speedtest.pdf"
set grid
#set style data lines
#set xdata time
set timefmt '%Y-%m-%d:%H:%M:%SZ'
#set xrange ["2022-01-19T00:00:00.0Z":"2022-01-24:00:00:00.0Z"]
set xrange [*:*]
plot "test.csv" using 4:7 with linespoints
Ethan's set datafile separator comma and your set datafile separator ',' should be equivalent.
Two little details:
your time format should be %Y-%m-%dT%H:%M:%SZ not %Y-%m-%d:%H:%M:%SZ. Find the difference!
# at the beginning of a line makes it a comment. So, remove # in the line #set xdata time
By the way, you could also just enter set xrange ["2022-01-19":"2022-01-24"]. If gnuplot will not find hours, minuts, seconds, I guess it will assume them to be zero.
Check the following slightly modified code.
Code:
### plotting timedata
reset session
$Data <<EOD
Server ID,Sponsor,Server Name,Timestamp,Distance,Ping,Download,Upload,Share,IP Address
4981,SELCO,"Shrewsbury, MA",2022-01-19T17:45:00.941297Z,46.02761207264913,16.34,202120227.4774976,5410786.336552021,,66.30.193.6
27031,BELD Broadband,"Braintree, MA",2022-01-19T18:45:01.962140Z,26.98449241976281,17.566,140849719.78516415,5441730.586693773,,66.30.193.6
27031,BELD Broadband,"Braintree, MA",2022-01-19T19:15:01.589345Z,26.98449241976281,17.419,156811809.4210379,5371285.306441804,,66.30.193.6
38849,FiberCast,"Stoddard, NH",2022-01-19T19:45:00.746522Z,106.41034005246897,20.042,215161640.72859222,6086086.612413734,,66.30.193.6
EOD
set datafile separator ","
set key autotitle columnhead
set xdata time
set timefmt '%Y-%m-%dT%H:%M:%SZ'
set xrange ["2022-01-19":"2022-01-24"] # specific range
set xrange [*:*] # autorange
set format x "%H:%M"
set grid
plot $Data using 4:7 w lp pt 7
### end of code
Result:
My data looks like this
1; 11.02.20; 6322; 00:12:38
2; 12.02.20; 6184; 00:10:57
3; 13.02.20; 6237; 00:11:17
4; 14.02.20; 5029; 00:08:16
I want to plot a bar graph for each entry in the 4th column and have the entries in the second as labels. But when I set the y-axis to the right time format the labels underneath vanish.
set boxwidth 0.7
set style fill solid
set datafile separator ";"
set timefmt "%H:%M:%S"
set format y "%M:%S" time
set ydata time
set yrange["00:00:00":"00:20:00"]
plot 'woche1.txt' using 4:xtic(2) with boxes
How can I fix this. Also, is it possible to have the values in the third column above each bar?
Which version of gnuplot are you running? With gnuplot 5.2.x, I would do it like this:
Code:
### time data on y-axis, with xtic() and labels
reset session
$Data <<EOD
1; 11.02.20; 6322; 00:12:38
2; 12.02.20; 6184; 00:10:57
3; 13.02.20; 6237; 00:11:17
4; 14.02.20; 5029; 00:08:16
EOD
set boxwidth 0.7
set style fill solid
set datafile separator ";"
myTimeFmt = "%H:%M:%S"
set format y "%M:%S" time
set yrange[strptime(myTimeFmt,"00:00:00"):strptime(myTimeFmt,"00:20:00")]
plot $Data u 0:(timecolumn(4,myTimeFmt)):xtic(2) with boxes notitle, \
'' u 0:(timecolumn(4,myTimeFmt)):3 w labels offset 0,1 not
### end of code
Result:
Addition:
If you have more than a few boxes to plot, I would not use xtic() as the xlabels if the x-axis is actually a time axis. Simply define it as time axis. Then gnuplot will take care about the labels, i.e. reduce them if there would be too many.
Code:
### time data on x-axis and y-axis
reset session
# generate some test data
set print $Data
today = time(0)
do for [i=0:14] {
day = strftime("%d.%m.%y", today + i*86400) # dates from today on
number = int(rand(0)*4000)+2000 # random integer between 2000 and 6000
time = strftime("%H:%M:%S", int(rand(0)*3600)) # random time within 1 hour
print sprintf("%d; %s; %d; %s",i,day,number,time)
}
set print
set boxwidth 86400*0.7 # box width 0.7 of a day
set style fill solid
set datafile separator ";"
myTimeFmtX = "%d.%m.%y"
set format x "%d.%m." time
myTimeFmtY = "%H:%M:%S"
set format y "%tM:%S" time
set yrange[strptime(myTimeFmtY,"00:00:00"):strptime(myTimeFmtY,"01:00:00")]
plot $Data u (timecolumn(2,myTimeFmtX)):(timecolumn(4,myTimeFmtY)) with boxes notitle, \
'' u (timecolumn(2,myTimeFmtX)):(timecolumn(4,myTimeFmtY)):3 w labels font ",8" offset 0,1 not
### end of code
Result:
I have two different text files which have a data column and a value column each. Ĩ wanted to plot both using a 'plot for' loop but I wanted to changed the name of the output to match the file I'm plotting. Right now my code looks like this:
set terminal postscript eps color
set out "test.eps"
set size 0.6
set multiplot
set xdata time
set timefmt "%Y-%m"
set format x "%b\n%y"
set xtics "2004-01", 12*2629746, "2016-12"
filenames = 'ArcheryData.txt CanyoningData.txt'
plot for [file in filenames] file u 1:2 w l title file
What I get now is the test.eps file which has the two data files plotted in the same graph.
In that case, you might use the do loop as:
set terminal postscript eps color
set size 0.6
set xdata time
set timefmt "%Y-%m"
set format x "%b\n%y"
set xtics "2004-01", 12*2629746, "2016-12"
do for [ name in "ArcheryData CanyoningData" ]{
set output name.".eps"
plot name.".txt" u 1:2 w l title name
}
Alternatively, the variable name could be specified when invoking Gnuplot, thus with a script as:
set terminal postscript eps color
set size 0.6
set xdata time
set timefmt "%Y-%m"
set format x "%b\n%y"
set xtics "2004-01", 12*2629746, "2016-12"
set output name.".eps"
plot name.".txt" u 1:2 w l title name
one might then use it as gnuplot -e "name='ArcheryData';" fig.gpl
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
I'm trying to plot last 24 hours from datafile. This data file has
date/time and value
Below are the contents of datafile.dat:
2015-12-17-21:07:41,74.30
2015-12-17-21:08:41,74.10
2015-12-17-21:08:41,74.10
2015-12-30-21:08:41,79.10
2015-12-30-21:09:41,79.10
....
below gnuplot script
set datafile separator ","
set terminal png font arial 12 size 1000,600
set xdata time
set timefmt "%Y-%m-%d-%H:%M:%S"
set format x "%d/%m\n%H:%Mh"
set xrange [ time(0) - 86400 : time(0) ] # 86400 sec = 1 day
set grid
set output "/data/weather/humidity.png"
plot "datafile.dat" using 1:2 with lines smooth bezier title ""
As I don't have data in the file for day 29, why does gnuplot draw a line from day 29 to day 30?
I don't have rows in the data file for day 29, and I'd like to not draw them.
If I don't have 24 hours of data in the the file, I would like to draw just what I have.
How can I do that?
Gnuplot has an option set clip which controls how lines connecting to points outside the given range are drawn: set clip one, which is the default, draws lines between two points if one of the points is in-range. The line is clipped at the plot border. set clip two would plot line parts even if both points are out-range, but the line goes through the plot area.
Use unset clip to plot only lines between points which are both in-range.
set datafile separator ","
set xdata time
set timefmt "%Y-%m-%d-%H:%M:%S"
set format x "%d/%m\n%H:%Mh"
set xrange [ time(0) - 86400 : time(0) ]
unset clip
plot "datafile.dat" using 1:2 with lines title ""
Unfortunately, that doesn't work properly with smoothing, because gnuplot first does the smoothing between all points (in-range and out-range), and then only applies the clipping rules. In order to have the smoothing handles properly you must filter the points before handling them to gnuplot, e.g. with awk:
set datafile separator ","
set xdata time
set timefmt "%Y-%m-%d-%H:%M:%S"
set format x "%d/%m\n%H:%Mh"
set xrange [time(0) - 86400 : time(0)]
filter = '< awk -F, -v d="$(date -d''24 hours ago'' +''%F-%T'')" ''$1>=d'' datafile.dat'
plot filter using 1:2 with lines smooth bezier title ""
Note, that the comparison $1 >= d in awk is a string comparison, but that is fine for the time format you are using.
As Christoph already mentioned, apparently smooth will smooth the data also outside the current plotting range. However, there is no need for awk or external tools, you can do it with gnuplot only (hence platform-independent).
Simply filter the data outside the range with gnuplot via:
myFilter(col,t) = t<t0 ? NaN : column(col)
The script creates some random test data with some missing data gap. When plotting only a part of the range you will get the unwanted (and unexpected) smoothing with data outside the plotting range, although you set unset clip.
Script:
### smooth filtered data
reset session
myTimeFmt = "%Y-%m-%d:%H:%M:%S"
set datafile separator ","
# create some random test data
set table $Data
set samples 50
SecPerDay = 3600*24
t0 = time(0)
y0 = 100
plot '+' u (sprintf("%s,%g", strftime(myTimeFmt,t0=t0-3600),y0=y0+rand(0)-0.5)) w table, \
t0 = t0 - 3*SecPerDay, \
'+' u (sprintf("%s,%g", strftime(myTimeFmt,t0=t0-3600),y0=y0+rand(0)-0.5)) w table
unset table
set format x "%b %d" timedate
set key out noautotitle
set grid x,y
N = 3 # N last days
t1 = time(0)
t0 = t1 - N*SecPerDay
myFilter(col,t) = t<t0 ? NaN : column(col)
set multiplot layout 3,1
set title "full data range"
plot $Data u (timecolumn(1,myTimeFmt)):2 w l ti "data", \
'' u (timecolumn(1,myTimeFmt)):2 smooth bezier w l ti "smooth"
set title "limited range with unwanted smoothing outside range"
unset clip
set xrange[t0:t1]
plot $Data u (timecolumn(1,myTimeFmt)):2 w l ti "data", \
'' u (timecolumn(1,myTimeFmt)):2 smooth bezier w l ti "smooth"
set title "limited range with filter"
set xrange[t0:t1]
plot $Data u (t=timecolumn(1,myTimeFmt)):(myFilter(2,t)) w l ti "data", \
'' u (t=timecolumn(1,myTimeFmt)):(myFilter(2,t)) smooth bezier w l ti "smooth"
unset multiplot
### end of script
Result: