Gnuplot for loop output - gnuplot

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

Related

Bashscript with Gnuplot on .csv and timespace

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:

Gnuplot for a simple date-time plot

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:

All points y value undefined! in gnuplot

I'm getting this error:
line 0:all points y value undefined!
My code for gnuplot is:
set terminal png 8;
set output "skript01_31/image10.png";
set timefmt x "%Y-%m-%d %H:%M:%S";
set xdata time;
set format x "%H:%M";
set xlabel "Cas";
set ylabel "Hodnota";
set yrange [:];
set xrange ["2009-05-11 07:30:00":"2009-06-11 00:34:00"];
set title "skript01";
set grid;
plot 'skript01_31/gnuplot_file' using 1:3 with points pt 7 ps 1 title "./skript01.sh";
My data file:
[2009-05-11 07:30:00] 0
[2009-05-11 07:31:00] 0.00999983333416666468
[2009-05-11 07:32:00] 0.01999866669333307936
[2009-05-11 07:33:00] 0.02999550020249566076
[2009-05-11 07:34:00] 0.03998933418663415945
[2009-06-11 00:34:00] 0.05
What I'm doing wrong?
Thanks for answer.
For the time format, this should be set timefmt x "[%Y-%m-%d %H:%M:%S]";, with the addition of the square brackets to match the time format used in the data file. Additionally the xrange variable should also acquire additional square brackets to match: set xrange ["[2009-05-11 07:30:00]":"[2009-06-11 00:34:00]"];

undefined variable: GPVAL_DATA_Y_MIN (Gnuplot)

Based on this post (I am using gnuplot gnuplot 4.6 patchlevel 1):
gnuplot: max and min values in a range
I am trying to use set yr [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX] in my .pg script that plots data from this .dat file:
100 2
200 4
300 9
But I get:
undefined variable: GPVAL_DATA_Y_MIN
This is my script:
set terminal png
set output 'img.png'
set xlabel 'x-label'
set ylabel 'y-label'
set boxwidth 0.5
set style fill solid
set yrange [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
plot 'sample.dat' with boxes title ""
Any ideas?
The gnuplot-defined variables are available only after a plot command (In the question you linked to, a replot is used to plot again).
Basically you have different options:
First plot to terminal unknown, and then change to the real terminal, set the range (now the variables are available), and replot:
set xlabel 'x-label'
set ylabel 'y-label'
set boxwidth 0.5 relative
set style fill solid
set terminal unknown
plot 'sample.dat' with boxes title ""
set terminal pngcairo
set output 'img.png'
set yrange [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
replot
Note, that I used the pngcairo terminal, which gives much better results, than the png terminal. And I used set boxwidth 0.5 relative.
Use set autoscale to fix the ranges instead of setting an explicit yrange. You can use set offset to specify a margin based on the autoscaled values:
set autoscale yfix
# set offset 0,0,0.5,0.5
plot 'sample.dat' with boxes title ''
Use the stats command to extract the minimum and maximum values:
stats 'sample.dat' using 1:2
set yrange[STATS_min_y:STATS_max_y]
plot 'sample.dat' with boxes title ''

Gnuplot, setting yrange days back

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"#

Resources