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.
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 have a data file data.txt, and data are as follows.
352 0.523240374 0.522909505 0.523471053
450 0.521095585 0.518197521 0.521120231
571 0.514979782 0.517518353 0.517105300
856 0.517216354 0.517600585 0.515035365
1259 0.514126520 0.514697120 0.514651830
2302 0.510628639 0.510990627 0.511418731
5276 0.507016704 0.507616124 0.505787979
And I wrote a gnuplot script plot.gpl, the code is
set term pdf enhanced font "Sans, 12"
set grid
set xlabel "Num of Cell"
set xrange [0:5500]
set ylabel "Numerical result"
set yrange [0.5:0.53]
set output "pic.pdf"
file = "data.txt"
plot file u 1:2 with linespoints ls 1 lw 0.1 ps 0.4 title "M11",\
file u 1:3 with linespoints ls 2 lw 0.1 ps 0.4 title "M22",\
file u 1:4 with linespoints ls 3 lw 0.1 ps 0.4 title "M33"
Then I typed the command gnuplot plot.gpl, a pdf file was generated, but only the first row of data.txt was plotted.
I tried to modify the format of data.txt, but failed.
Anyone can help me to solve this problem?
PS: Windows 10 Home, MSYS2: Mingw-w64 64 bit, gnuplot 5.2.0
For the sake of not letting this question appear unanswered. I guess according to SO "rules": no answers in comments.
Looks like you only have one line of data. Do you maybe have a text file which has been created on MacOS? Could you check your line end character? Is it \n (LF) (Linux) or \r\n (CR LF) (Windows) or \r (CR) (MacOs)? In the latter case you would get only the first row like you get.
I have data recorded in time. But some data lines are missing and gnuplot replace them with long lines in these intervals.
How can i set gnuplot to draw nothing instead of draw lines in these intervals?
PS. I don't have free cells in these lines, I dont have these lines at all.
lines:
column 1 ... col 195
13:30:20.8 0.78061899
13:30:21.8 5.969546498
13:32:19.8 17.21257881
13:32:20.8 6.922475345
If you don't want to draw a line between two points you must insert an empty line in the data file between the two point entries, so that effectively you have
13:30:20.8 0.78061899
13:30:21.8 5.969546498
13:32:19.8 17.21257881
13:32:20.8 6.922475345
This cannot be done with gnuplot directly, but you can use e.g. awk to do the processing on-the-fly:
set timefmt '%H:%M:%S'
set xdata time
filename = 'data.txt'
plot 'awk ''{split($1,d,":"); t_prev = t; t = (d[1] * 60 + d[2])*60 + d[3]; if (t_prev && (t - t_prev > 10)) print ""; print }'' '.filename with lines
Here, the gap threshold is 10 seconds.
I suppose your miss data identifier is "NaN", then you can use the following command
plot "data" using 1:($2) with linespoints
instead of
plot "data" using 1:2 with linespoints
The former one will ignore the missing data and treat it as blank line and therefore not draw a connecting line across the gap while the latter one will draw continuous, unbroken line.
Just for the records: there are later questions about the same/similar issue.
Avoid connection of points when there is empty data
How to remove line between "jumping" values, in gnuplot?
Removing vertical lines due to sudden jumps in gnuplot
However, my solutions there require transparent color, which was not available in at the time of OP's question (gnuplot 4.6.5, Feb 2014). Nevertheless, there is a solution without external tools like awk or changing the data.
First solution for gnuplot 4.6.: Instead of a transparent line you use a white line which, however, will cover the grid lines, although it will be hardly visible.
Second solution for gnuplot 4.6 is using vectors. This really interrupts the line and will work for gnuplot 5.x as well.
Data:
00:00:00 0.406406
00:00:44 0.339779
00:01:28 0.986602
00:02:13 0.17746
00:02:57 0.0580277
00:03:42 0.586614
00:04:26 0.84247
00:05:11 0.597502
00:05:55 0.0394846
00:06:40 0.369416
00:13:20 0.527109
00:13:42 0.371411
00:14:04 0.851465
00:14:26 0.980312
00:14:48 0.431391
00:15:11 0.545491
00:15:33 0.708445
00:15:55 0.861669
00:16:17 0.277122
00:16:40 0.787273
Script:
### avoid showing a line across larger time gaps
reset
FILE = "SO26510245.dat"
myFmt = "%H:%M:%S"
tGap = 60 # 60 seconds
set format x "%H:%M"
set timefmt "%H:%M:%S"
set xdata time
set ytics 0.5
set key top center noautotitle
set grid x,y
set multiplot layout 3,1
plot FILE u 1:2 w l lc rgb "red" ti "data as is"
myColor(col) = (t0=t1, t1=timecolumn(1), t1-t0>tGap ? 0xffffff : 0x0000ff)
plot t1=NaN FILE u 1:2:(myColor(1)) w l lc rgb var ti "white line"
myGap(col) = (t1-t0>tGap ? NaN : y0)
plot t1=y1=NaN FILE u (t0=t1,t1=timecolumn(1),t0):(y0=y1,y1=$2,myGap(0)):(t1-t0):(y1-y0) \
w vec lc rgb "web-green" nohead ti "with vectors"
unset multiplot
### end of script
Result: (created with gnuplot 4.6.0, from March 2012)
I am using ubuntu 14.04, gnuplot 4.6 patchlevel 4.
I have the following script, named Plot.script:
## GNUPLOT command file
set terminal postscript color
set style data lines
set noxzeroaxis
set noyzeroaxis
set key top spacing .8
set size ratio 0.821894871074622
set noxtics
set noytics
set title 'Combined DET Plot'
set ylabel 'Miss probability (in %)'
set xlabel 'False Alarm probability (in %)'
set grid
set pointsize 3
set ytics (\
'5' -1.6449, '10' -1.2816, '20' -0.8416, '40' -0.2533, '60' 0.2533, \
'80' 0.8416, '90' 1.2816, '95' 1.6449, '98' 2.0537)
set xtics (\
'.0001' -4.7534, '.001' -4.2649, '.004' -3.9444, '.01' -3.7190, '.02' -3.5401, \
'.05' -3.2905, '.1' -3.0902, '.2' -2.8782, '.5' -2.5758, '1' -2.3263, \
'2' -2.0537, '5' -1.6449, '10' -1.2816, '20' -0.8416, '40' -0.2533)
plot [-4.75343910607888:-0.253347103317183] [-1.64485362793551:2.05374890849825] \
-x title 'Random Performance' with lines 1,\
'tmp/score.det.sub00.dat.1' using 3:2 title 'Term Wtd. fake : ALL Data Max Val=0.267 Scr=0.436' with lines 2,\
'tmp/score.det.sub00.dat.2' using 6:5 notitle with points 2,\
'tmp/score.det.sub01.dat.1' using 3:2 title 'Term Wtd. fake: CTS Subset Max Val=0.267 Scr=0.436' with lines 3,\
'tmp/score.det.sub01.dat.2' using 6:5 notitle with points 3
Then I run gnuplot Plot.script | ps2pdf - .
I get the following error:
line 27: ';' expected
line 27 is the last row of the script:
'tmp/score.det.sub01.dat.2' using 6:5 notitle with points 3
I have searched from web and found this similar question but it doesn't seem to help. Does anyone know what the problem is?
In general it is very hard to debug such a long script, especially without having the test data to run exactly this script. You should start by cutting down your script line by line to track down in which line the error really appears. The whole plot command is treated as a single line, so if it says line 27, the error can also appear earlier.
I guess, that you have the wrong syntax for selecting line types. Using with lines 1 doesn't work, and the simple line
plot x with lines 1
already shows this error. You must use
plot x with lines linetype 1
Accordingly you must fix all other positions where you set a line type (or point type).
line 27: ';' expected
can mean there's a ',' missing in the plot statement. I couldn't find it myself in your code. May be you need to delete blanks before "Scr="
But I had a similar problem.
I have a shell script that performs some calculations and plot the results. I have used gnuplot for plotting the results. I'm facing two problems. I used to run the script on my cygwin and it's Okay. When I tried to run it on Ubuntu (Version 10.04-wubi-version), it couldn't recognize the png files (set terminal png unknown). I have tried to install (missing libraries that support "libgd2_2.0.36~rc1~dfsg" and update the libraries.... no luck !! then I have decided to use set terminal pdf instead since I found it supported :
here is my gnuplot version:
G N U P L O T
Version 4.4 patchlevel 0
last modified March 2010
System: Linux 2.6.35-32-generic
here is the output of terminal types:
latex LaTeX picture environment
mf Metafont plotting standard
mif Frame maker MIF 3.00 format
mp MetaPost plotting standard
nec_cp6 NEC printer CP6, Epson LQ-800 [monocrome color draft]
okidata OKIDATA 320/321 Standard
pbm Portable bitmap [small medium large] [monochrome gray color]
pcl5 HP Designjet 750C, HP Laserjet III/IV, etc. (many options)
-->pdf PDF (Portable Document File) file driver
postscript PostScript graphics, including EPSF embedded files (*.eps)
pslatex LaTeX picture environment with PostScript \specials
pstex plain TeX with PostScript \specials
Now, After I have modified the shell script to use pdf, I'm getting this error (Note: some of the pdf files are created ).
line 0: ';' expected
Again, I've added ';' to all of the lines.... and the error still appears.
Here is part of my shell script (that gives the error):
gnuplot << TOEND ;
set terminal pdf;
set output 'A.pdf';
set autoscale ;
#unset log
#unset label
set xtic auto ;
set ytic auto ;
set title "title";
set xlabel "x axis";
set ylabel "y axis";
######################################
#UPDATE: I have added double space to a void the error
######################################
plot "A1.tr" using 1:2 title "A" with lines 9, \
"A2.tr" using 1:2 title "B" with lines 11
the output (Note this part is not of the created pdf files):
line 0: invalid character \ --->pointing to 9, \
line 0: invalid command --->poiting to A2.tr
the rest of shell script produces the same error (Note: output is created)
......
......
######################################
#UPDATE: #psibar pointed that 'ls' missing
######################################
plot "results.tr" using 1:2 title "Results" with lines ls 9;
^
line 0: ';' expected---> pointing to 9 ;
After long searching, I think the problem has to do with version of UBUNTU and Gnuplot....I don't want to upgrade my version of ubuntu.....
After solving the errors. Any suggestions on how to get the "set terminal png" works on ubuntu 10.04 ??
To solve the problem I have added ls and double spaces after the 9, \.
The final answer would be :
gnuplot << TOEND ;
set terminal pdf;
set output 'A.pdf';
set autoscale ;
#unset log
#unset label
set xtic auto ;
set ytic auto ;
set title "title";
set xlabel "x axis";
set ylabel "y axis";
######################################
#UPDATE: I have added double space to a void the error
# and #psibar pointed that 'ls' was missing
######################################
plot "A1.tr" using 1:2 title "A" with lines ls 9, \
"A2.tr" using 1:2 title "B" with lines 11