I have a file with data in this format:
1351649601.045 421 2945
1351649601.684 1036 28591
1351649603.310 128 1620
1351649603.413 93 0
1351649603.375 132 1762
1351649603.318 218 1761
1351649603.434 412 176
1351649603.441 520 5780
1351649603.480 565 11070
1351649603.556 644 11535
gnuplot> set term png
Terminal type set to 'png'
gnuplot> set output "output.png"
gnuplot> plot "data.txt" using 1:2 with lines
however, the date is not read properly by gnuplot. Do you have any ideas?
solved:
set term png xffffff
set output "output.png"
set size 17,17
set title "HTTP payload size and response time"
set style data fsteps
set xlabel "Date"
set timefmt "%s"
set format x "%m/%d/%Y %H:%M:%S"
set xdata time
set ylabel "Payload/Response time"
set grid
set key left
plot 'response' usi 1:2 with linespoints
Sorry, can't seem to delete. Was going to suggest:
set xdata time
set timefmt "%s"
set format x "%m/%d/%Y %H:%M:%S"
plot "file.txt" using 1:2 with linespoints
But it truncates the fraction and drops points from the line.
Related
I would like to see the number of events per timeperiod.
My rows look like this
"2020-11-11 09:15:50",field2,field3
This is what I have tried
binwidth = 3600 # 1h in seconds
bin(t) = (t - (int(t) % binwidth) + binwidth/2)
set datafile separator ","
#set xdata time
set timefmt '"%Y-%m-%d %H:%M:%S"'
set boxwidth binwidth
plot 'Statistics.log' using (bin(timecolumn(1, '"%Y-%m-%d %H:%M:%S"'))):(1) smooth freq with boxes
I'm getting
unknown type in magnitude()
How would I debug errors like these? (How do I dump what gnuplot "sees" for timecolumn() etc.?)
(gnuplot 4.6)
At first, The timecolumn() in gnuplot 4.6 is a single-argument function, and only the argument for the column number is allowed. Therefore, the plot command can be rewritten as,
plot "test.dat" using (bin(timecolumn(1))):(1) smooth freq with boxes
Secondly, do not include leading and trailing double quotes in your timefmt formatting.
set timefmt '%Y-%m-%d %H:%M:%S'
For more information about this, please refer to the "help data" section.
...
However, whitespace inside a pair of double quotes is ignored when
counting columns, so the following datafile line has three columns:
1.0 "second column" 3.0
Finally, your code can be modified as follows (for gnuplot 4.6)
binwidth = 3600 # 1h in seconds
bin(t) = (t - (int(t) % binwidth) + binwidth/2)
set datafile separator ","
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set boxwidth binwidth
plot 'Statistics.log' using (bin(timecolumn(1))):(1) smooth freq with boxes
A few minutes too late... while testing... #binzo basically already answered.
The only difference: if your data uses double quotes for the date
"2020-11-11 09:15:50",field2,field3`
and you don't want to change your existing data, you have to specify it in set timefmt. For some strange reason which I cannot explain right now, if you set datafile separator "," it will mess up the graph, but it seems to work without.
Code: (tested with gnuplot 4.6.0)
### timedata in histogram (gnuplot 4.6)
reset
FILE = 'Statistics.log'
myTimeFmt = '"%Y-%m-%d %H:%M:%S"'
# create some test data
myDate = strptime(myTimeFmt, '"2020-11-11 11:11:11"')
myRandomDate(n) = myDate + 3*3600*invnorm(rand(0))
set print FILE
do for [i=1:500] {
print sprintf("%s,%g,%g",strftime(myTimeFmt,myRandomDate(0)),rand(0),rand(0))
}
set print
# set datafile separator "," # if uncommented this will messup the plot, don't know why
set xdata time
set format x "%Y-%m-%d\n%H:%M"
set timefmt '"%Y-%m-%d %H:%M:%S"'
binwidth = 3600 # 1 h in seconds
bin(t) = (t - (int(t) % binwidth) + binwidth/2)
set boxwidth binwidth
set style fill solid 0.5
set xtics 4*3600 # 4 h in seconds
plot FILE u (bin(timecolumn(1))):(1) smooth freq w boxes notitle
### end of code
Result:
I am trying to plot time vs entropy of a data. When I run the script, it just produces a graph with one dot on y axis and no plot. Here is my script:
set terminal png
set output 'output.png'
set xdata time
set timefmt '"%Y-%m-%d %H:%M:%S"'
set format x '"%Y-%m-%d %H:%M:%S"'
set xrange ['"2008-01-01 00:00"':'"2008-03-20 00:00"']
set yrange [0.5:2.4]
set style data lines
set xlabel "Time"
set ylabel "Entropy"
plot "foobar-entropy.txt" using 1:2 w lp ls 4 lw 3
And here is the data:
"2008-01-01 02:13:38" 1.0
"2008-01-10 02:12:13" 1.5
"2008-01-20 02:11:55" 1.459
"2008-01-30 02:10:28" 1.811
"2008-02-10 02:09:44" 1.722
"2008-02-20 02:08:00" 1.65
"2008-02-28 02:07:00" 2.149
"2008-03-10 02:06:00" 2.18
"2008-03-20 02:04:00" 2.33
Any help would be appreciated.
Finally, found the mystery after #Christoph told about the line breaks. The issue was that the file had different line endings which gnuplot do not support.
When I opened the file with vi editor it appeared as follows:
"2008-01-01 02:13:38" 1.0^M
"2008-01-10 02:12:13" 1.5^M
"2008-01-20 02:13:55" 1.459^M
"2008-01-30 02:12:28" 1.811^M
"2008-02-10 02:12:44" 1.722^M
"2008-02-20 02:13:00" 1.65^M
"2008-02-28 02:13:00" 2.149^M
"2008-03-10 02:13:00" 2.18^M
"2008-03-20 02:13:00" 2.33^M
After running the command dos2unix on the file, it changed the old-style carriage-return characters to linefeeds and it works fine now.
I have data files from 20 GB to 50 GB each. I want to draw plots using theses files which I later use to make small videos. My Gnuplot script is as follows:
unset xtics
unset ytics
unset key
unset border
set xrange [0:12.8]
set yrange [0:7.2]
set cbrange [0:1]
set size ratio -1
set term png
file = "hugeDataFile.dat"
sizeX = 1280
sizeY = 720
lines = sizeX*sizeY
numberOfImages = 1500
do for [i=1:numberOfImages]{
set terminal png size sizeX, sizeY
set output sprintf('%05d.png', i)
start = (i-1)*lines+1
end = i*lines
plot file every ::start::end u 1:2:3 pt 5 ps 0.4 pal
}
The problem is, it takes more than 48 hours to plot those 1500 .png images from a 31 GB data file. Is there any way to accelerate that process? Can I make the Gnuplot script more efficient?
I have a python script that I write out a .gnu file and it plots a .png file. I am trying to make the yrange more dynamic by setting the range to be 5% of the max and min.
What am I doing wrong?
This code will not run like this.
#-- write out .gnu file
self.output = textwrap.dedent('''\
set terminal png size 800,600
set output "{0}"
set grid
set xlabel "Cycle"
set title "{1}"
set xtics ({2})
set yrange[GPVAL_Y_MIN:GPVAL_Y_MAX]
plot ''').format(self.figurename, self.title, ",".join(plot_data.keys()), self.styletype, self.datafile)
for n in range(0,max_num_lines):
tmp_str = " ".join(['"{2}"','using','1:'+str(n+2),'title',"'"+self.titles[n+1]+"'",'w linespoints {1}']).format(self.figurename, self.linecombos[n], self.datafile)
if n!=max(range(0,max_num_lines)):
tmp_str += ", "
self.output += tmp_str
pass
The internal variables GPVAL_Y_MIN/GPVAL_Y_MAX are not initialized until you actually plot something. To circumvent this, you might use the stats command which analyzes a file and provides the desired min/max values via the STATS_min_y/STATS_max_y variables:
self.output = textwrap.dedent('''\
set terminal png size 800,600
set output "{0}"
set grid
set xlabel "Cycle"
set title "{1}"
set xtics ({2})
#analyze the file and adjust y-range
stats "{3}" nooutput
set yrange[STATS_min_y:STATS_max_y]
plot ''').format(self.figurename, self.title, ",".join(plot_data.keys()), self.styletype, self.datafile)
I’m trying to develop a histogram script. The plot itself seems correct, but I have some problems or questions:
I don’t understand why the “stats” output says my data file has “out of range” points. What does that mean?
The “stats” minimum value doesn’t look correct, either. From the data file, minimum = -0.0312, but stats reports 0.0.
The script:
# Gnuplot histogram from "Gnuplot In Action", 13.2.1 Jitter plots and histograms (p. 256)
# these functions put data points (x) into bins of specified width
bin(x,width) = width*floor(x/width)
binwidth = 0.01
set boxwidth binwidth
# data file
data_file = "sorted.csv"
png_file = "sorted.png"
datapoint_count = 14
# taking explanations from the data file
set style data linesp
set key autotitle columnheader
set datafile separator "," # CSV format
# histogram
myTitle = "Histogram from \n" . data_file
set title myTitle
set style fill solid 1.0
set xlabel "Slack"
set mxtics
set ylabel "Count"
set yrange [0:*] # min count is always 0
set terminal png # plot file format
set output png_file # plot to file
print "xrange="
show xrange
print "yrange="
show yrange
stats data_file using ($1)
print "STATS_records=", STATS_records
print "STATS_invalid=", STATS_invalid
print "STATS_blank=", STATS_blank
print "STATS_min=", STATS_min
print "STATS_max=", STATS_max
plot data_file using (bin($1,binwidth)):(1) smooth frequency with boxes
The data file:
slack
-0.0312219
-0.000245109
-4.16338e-05
-2.08616e-05
-1.82986e-05
8.31485e-06
1.00136e-05
1.23084e-05
0
0.000102907
0.000123322
0.000138402
0.19044
0.190441
The output:
gnuplot sorted.gp
Could not find/open font when opening font "arial", using internal non-scalable font
xrange=
set xrange [ * : * ] noreverse nowriteback # (currently [-10.0000:10.0000] )
yrange=
set yrange [ 0.00000 : * ] noreverse nowriteback # (currently [:10.0000] )
* FILE:
Records: 9
Out of range: 5
Invalid: 0
Blank: 0
Data Blocks: 1
* COLUMN:
Mean: 0.0424
Std Dev: 0.0792
Sum: 0.3813
Sum Sq.: 0.0725
Minimum: 0.0000 [3]
Maximum: 0.1904 [8]
Quartile: 0.0000
Median: 0.0001
Quartile: 0.0001
STATS_records=9.0
STATS_invalid=0.0
STATS_blank=0.0
STATS_min=0.0
STATS_max=0.190441
If you give a single column to the stats command, the yrange is used to select the range from this column.
At first sight this doesn't make sense, but behaves like a plot command which has only a single column, in which case this single column is the y-value and the row number is choosen as x-value.
So, just move the set yrange part behind the stats command.
data_file = 'sorted.csv'
stats data_file using 1
show variables all
set yrange [0:*]
plot data_file ...