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:
Related
I am trying to extract a string from a csv capture. I am trying to plot labels on the graph.
these are the first few lines (variable amount):
Time,SecExec
26/May/2022:00:08:07,0.666
26/May/2022:00:19:05,0.720
26/May/2022:00:20:33,0.965
26/May/2022:00:28:01,0.662
26/May/2022:00:28:38,1.090
26/May/2022:06:07:41,0.016
26/May/2022:06:09:07,1.194
26/May/2022:06:16:36,0.017
26/May/2022:06:36:37,0.743
26/May/2022:06:56:37,0.737
26/May/2022:07:09:16,0.006
26/May/2022:07:09:16,0.006
26/May/2022:07:10:55,0.009
26/May/2022:07:16:36,0.014
26/May/2022:07:16:39,0.008
26/May/2022:07:18:22,0.696
My execution code:
reset session
N1 = ARG1 #Title
N2 = ARG2 #File name
set datafile separator ','
set xdata time
set timefmt "%d/%m/%Y:%H:%M:%S"
set ylabel "Tiempo" font ",11"
set title N1 font ",14"
set format x "%d/%m/%Y:%H:%M:%S"
set xlabel "Fecha" font ",11"
set boxwidth 2.0 relative
set style fill solid 0.4
set grid x,y
set term png size 1200, 720
set output sprintf("numbers.png")
plot N2 u 1:2 w lp lw 1.5 lc 7
set output
My input in terminal:
gnuplot -c "codedata" "graphic-title" "archic.csv"
If I use this manual in the Gnuplot Terminal, it plots the desired data. The problem is that the execution leaves a range of invalid fields
You are using the wrong time specifier. You should use %b or %B depending if you have abbreviated or full month names. Check help time_specifiers.
Script:
### plot time data with month name
reset session
$Data <<EOD
Time,SecExec
26/May/2022:00:08:07,0.666
26/May/2022:00:19:05,0.720
26/May/2022:00:20:33,0.965
26/May/2022:00:28:01,0.662
26/May/2022:00:28:38,1.090
26/May/2022:06:07:41,0.016
26/May/2022:06:09:07,1.194
26/May/2022:06:16:36,0.017
26/May/2022:06:36:37,0.743
26/May/2022:06:56:37,0.737
26/May/2022:07:09:16,0.006
26/May/2022:07:09:16,0.006
26/May/2022:07:10:55,0.009
26/May/2022:07:16:36,0.014
26/May/2022:07:16:39,0.008
26/May/2022:07:18:22,0.696
EOD
set datafile separator ','
set xdata time
set timefmt "%d/%b/%Y:%H:%M:%S"
set xlabel "Fecha" font ",11"
set format x "%b %d\n%H:%M"
set ylabel "Tiempo" font ",11"
set grid x,y
plot $Data u 1:2 w lp lw 1.5 lc 7
### end of script
Result:
I plot a time-series of datas (images, throughput), using this:
set term postscript color eps enhanced 22
set encoding utf8
set output "tput.eps"
load "../styles.inc"
set size 1,0.6
set bmargin 4.5
set tmargin 2.5
set lmargin 9
set rmargin 8
set title "{/bold Images updated and generated network traffic}" offset 0,0
set ylabel "#Images" offset 0,0
set y2label "Throughput [GB/day]" offset -2,0
set ytics 0,100,800
set ytics nomirror
set y2tics 0,100,600
set y2tics nomirror
set xtics time
set format x '%d/%m/%Y'
set grid y
set yrange[0:800]
set y2range [0:]
set xtics rotate by 45 right font "Arial, 18" nomirror
set key vertical sample 1.0 maxrows 1 width -0.6 at graph 1,1.13 font "Arial, 18"
set datafile separator ","
plot "datecount_sorted.csv" using (timecolumn(1, "%Y-%m-%d")):($2) with lines ls 5001 title "Uploaded images",\
"datecount_sorted.csv" using (timecolumn(1, "%Y-%m-%d")):($3/(1024*1024*1024)) axis x1y2 ls 5002 title "Upload Throughput",\
!epstopdf "tput.eps"
!rm "tput.eps"
quit
The input data looks like this:
2016-04-12,1,0
2016-05-02,2,0
2016-05-05,2,0
2016-05-06,1,0
2016-05-11,2,0
2016-05-13,3,0
2016-05-25,2,0
2016-06-01,3,541204241
2016-06-06,1,0
2016-06-13,1,471311979
2016-06-14,1,6329289
2016-06-17,1,137972881
2016-06-24,1,319050239
2016-06-27,1,138193384
The output is correct, it looks like this:
The problem is that when I try to set an xrange, the plot breaks completely (does not render).
This syntax in particular seems to be wrong:
set xrange ["2020-01-01":"2020-06-17"]
And similarly wrong is the one using the same timefmt that is used in the plot:
set xrange ["01/01/2020":"17/06/2020"]
So..what is the correct syntax ?
What you are missing is set xdata time and set timefmt <format string> to tell gnuplot how read the dates from the data, the xrange is set using the format specified in timefmt, which doesn't have to be the same as the format you give to the axis, the plot breaks because it can't decode the dates from the xrange.
In your case adding this should suffice
set xdata time
set timefmt "%Y/%m/%d"
I tested it with set xrange ["2016/04/12":"2016/05/03"] on the example data file you posted.
You must explicitely parse the time strings passed to the range settings:
set xtics time
FMT="%Y-%m-%d"
set format x "%d/%m/%Y"
set xrange [strptime(FMT, "2016-01-01"):strptime(FMT, "2016-06-17")]
set datafile separator commna
plot "datecount_sorted.csv" using (timecolumn(1, FMT)):2 with lines title "Uploaded images"
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:
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 put up a raspberry pi to measure temperature and call a Gnuplot script to place a graph on a webpage.
Now i want to make a couple of graphs that display 1hour backwards in time/1day backwards in time.
Does anyone know how i specify the X-range to start at "current time - 1 day" or "current time - 1 hour"?
Thanx!
This won't work everywhere, but if your gnuplot supports pipes and your system has the date command ...
TIMEFMT = "%Y:%m:%d:%H:%M:%S"
#now = "`date +%Y:%m:%d:%H:%M:%S`" #Use this line in production
now = '2013:01:24:20:49:30' #Hard-code this for the sake of the example ...
now_secs = strptime(TIMEFMT,now)
one_hour_past = now_secs - 3600.0
set xdata time
#set timefmt TIMEFMT #This doesn't parse correctly ... Not sure why...
eval(sprintf('set timefmt "%s"',TIMEFMT))
print strftime(TIMEFMT,one_hour_past)
#set xrange [strftime(TIMEFMT,one_hour_past):] #This doesn't seem to work
#set xrange ["2013:01:24:20:49:30":] #This works, but is declared statically -- Yuck.
eval(sprintf('set xrange ["%s":]',strftime(TIMEFMT,one_hour_past)))
plot '-' u 1:2 w l
2013:01:24:10:00:00 2.5
2013:01:24:21:00:00 2
2013:01:24:22:00:00 3
e
THe code i have used is as follows. Im running it on a Raspberry Pi with Rasbian OS. Any sudgestions? Thanx!
#!/usr/bin/gnuplot
reset
set terminal png size 1250,700
set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"#E6E6FA" behind
set output '/var/www/bild.png'
set multiplot
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%H:%M\n%d/%m"
set xlabel "Timme/datum"
set ylabel "Inomhustemperatur"
set yrange [15:28]
set y2label "Utomhustemperatur"
set y2range [-20:10]
set y2tics nomirror
set y2tics
set title "Temperatur"
set key reverse Left outside
set grid
set style data lines
plot "logg.txt" using 1:3 axes x1y1 lw 3 title "inomhus", "" using 1:4 axes x1y2 lw 3 title "utomhus"#