Gnuplot misreads time data - gnuplot

I can't seem to get gnuplot to properly plot my time data. (I'm using version 4.6, patchlevel 3.)
For an MWE (well, non-working...), the input file
reset
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"
plot '-' using ($1):($2) with lines lw 3
15:36:12 1.0
15:43:17 3.0
16:12:02 2.0
e
produces the following output:
Apparently, gnuplot interprets the hours as seconds and ignores the rest. I have tried a bunch of other format strings (also single/double quotes), but gnuplot seems to ignore everything except the first number.
Is something wrong with my format, or is this a bug, or something else?

With $1 you explicitely select the numerical value of the first column, which bypasses any gnuplot automatism to interpret the column values as appropriate (as time value in your case). Simply use using 1:2:
reset
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"
plot '-' using 1:2 with lines lw 3
15:36:12 1.0
15:43:17 3.0
16:12:02 2.0
e
Use the syntax $1 only when doing calculations with the actual numerical value in the respective column. $1 is a shortcut for column(1), gnuplot also knows stringcolumn(1) and timecolumn(1) for other purposes.

Related

Gnuplot using time as x-axis

I am trying to use gnuplot from a csv file. There are quite a bit of similar posts but I haven't had any success from them. There should be 4 lines marked by the integer values and the times should make up the x axis.
data file: first column is H:M:S, rest are 0-100 values
00:26:45,34,12,3,7
00:27:14,31,10,5,9
00:27:43,27,7,2,4
00:28:18,32,11,4,6
00:28:45,36,17,6,7
00:29:35,39,16,1,3
00:30:48,24,12,5,4
00:31:33,32,9,2,8
00:32:15,27,12,3,7
00:32:45,34,15,6,4
gnuplot commands:
set datafile separator ","
set yrange [0:100]
set xrange ["00:00:00":"24:00:00"]
set xtics format '%H:%M:%S'
set timefmt '%H:%M:%S'
set xdata time
plot 'test.csv' using 1:2 with lines
So far all I get is a blank plot with 5 second increments starting at 00:00:00.
Any help would be greatly appreciated.
I was able to get the plot to show correctly by removing the xrange line. But the x-axis still doesnt display the exact times from the first column, Just every hour. Seems to just be a matter of more formatting.

Gnuplot construct timefmt from different CSV columns?

I have the following csv file in which the columns represent hour,minute,view count respectively, exactly 1440 entries for every minute of the day. I would like to plot it using gnuplot. (Putting the HH:MM into one column is not possible due to the MySQL ONLY FULL GROUP BY.)
"0","0","71"
"0","1","55"
"0","2","56"
...
"23","57","66"
"23","58","70"
"23","59","75"
Currently I use the following commands:
set datafile separator ","
set timefmt "%H,%M"
set xdata time
set xtics format "%H:%M" time font "/:normal,8" rotate by 45 offset -1,-1
The time format is not rendered correctly, the hours are interpreted as minutes and the minutes are not shown at all.
I also tried set timefmt "\"%H\",\"%M\"" without success.
Two questions:
How can I parse the hour:minute and display it correctly?
If this data file had more columns and the timestamp was not in the first but in the n-th one, then how can I specify for gnuplot to render that, similar to using 0:n for plot?
Use this time format string
set timefmt "%H:%M"
Put this function somewhere:
catdate(x,y)=sprintf("%d:%d",x,y)
Then plot with:
plot 'data.dat' u (catdate($1,$2)):($3) w l

Turn Off Scientific Notation In Gnuplot

In gnuplot I've enabled logscale for my y axis, which gives me 1 to 1,000,000. However, the 1,000,000 tick appears in scientific notation. That stands out since its the only number in that form. I'd like to have it written as 1000000. All of my Google searches for disabling scientific notation, formatting as a decimal, or making the ytics space wider haven't produced anything that solves my problem.
The format of the axis tics is set either with set format x or set xtics format (equivalent commands for y, z, x2, y2 and cb exists as well).
Use show format to find out, which is the default format (result for 4.6.6, since 5.0 the default is % h)
gnuplot> show format
tic format is:
x-axis: "% g"
...
%g is a gnuplot-specific format specifier, but works similar to the C format specifiers used for sprintf and similar functions. The definition of %g according to the gnuplot documentation is: "the shorter of %e and %f". This is why the format can change for a single axis.
So, finally, to change to a fixed format for all tics, use e.g.
set format y '%.0f'

gnuplot: xdata time and boxes

I have some temperature data in a text file, and I would like to represent it in a 'boxed' plot, showing the temperature of each day like an histogram.
23 10 2012 12.3
28 10 2012 14.1
30 11 2012 30.4
...
I'm triying to represent it with a simiple gnuplot script like this:
set terminal png enhanced font font_file size size_x, size_y tiny
set xdata time
set timefmt "%d %m %Y"
set format x "%d"
set boxwidth 0.9 relative
plot u 1:4 w boxes
I would like to leave blank the days where no data is available, but gnuplot gives these days the value of the last day a data was available. For example, in the data file I wrote before, gnuplot would give a 12.3 to the 23th of october, but I would like leave this gap without any bar.
Is there a way to get this? I have discarted an histogram representation because I've read that it is not compatible with time data.
Thank you in advance
Your problem is the line set boxwidth 0.9 relative. Relative says that you're trying to fill 90% of the space between adjacent boxes. You probably want to set an absolute boxwidth. If you change your script to set boxwidth 0.9 absolute, then you'll see vertical lines. This is because when using time data, the x-axis unit is actually seconds, so your box is only ~1 second wide when your x-scale is multiple days. So, to get each box to be the width of a single day you would use
set boxwidth 3600*24
Here's the complete script:
set term png enhanced
set output 'foo.png'
set xdata time
set timefmt "%d %m %Y"
set format x "%d"
set boxwidth 3600*24
plot 'test.dat' u 1:4 w boxes
and the output:

Display powers of 2 on the axis with gnuplot

I am trying to use gnuplot to plot results from my experiments.
I wrote a C++ program that generates a datafile that looks like this:
10 3.5
11 3.5
12 3.5
13 3.6
What I am trying to do is to display the values of the first column of this datafile on the x-axis as powers of 2. It would look something like that (It doesn't have to look exactly the same):
http://i.stack.imgur.com/8BSLr.png
So with the datafile I posted, I want to have 2^10, 2^11, etc on the x axis.
Any idea how to do that?
I can change the format of the datafile if needed.
Thanks!
this is done relatively easy by manipulating the using specification:
plot datafile using (2**$1):2
If you do this, you'll probably also want a
set logscale x 2
set format x '2^{%L}' #<- enhanced text.
to make the plot look nicer.

Resources