|
From: <gn...@ze...> - 2015-10-21 10:01:49
|
Hi Gnuplot-info, I'm trying to plot data on a relative time scale starting at 0 the input is a column of seconds and a column of data. --------------------------- set xdata time set timefmt "%s" plot "-" using 1:2 with lp 0 0.0 1 0.5 2 1.0 3 1.5 EOF --------------------------- can someone explain why I get these results: http://i.imgur.com/lBmk5di.png The data should be a straight line, but gnuplot seems to have a problem dividing the X asis when using time. Thank you, -- :wq ^X^Cy^K^X^C^C^C^C |
|
From: Ico <gn...@ze...> - 2015-10-21 12:58:28
|
Hi Marek, * On 2015-10-21 14:43:02 +0200, Marek W. Gutowski wrote: > Your commands before plotting should be: > > set xdata time > set timefmt x "%S" > set format x "%S" > 1. note "S" (uppercase, not lowercase) Tried %S as well, but this breaks down as soon as the time in seconds exceeds 100: http://i.imgur.com/aUVNb2a.png So I must still be doing something wrong? > 2. note information about time format both for data AND for plot Actually I want the X axis to show time in [HH]:MM:SS format, which is the reason to choose 'xdata time' at first. So: - input time is seconds starting at 0 - output is time in 'human friendly' notation [HH]:MM:SS ------------------------- set xdata time set timefmt "%S" set format x "%S" plot "-" using 1:2 with lp 1 0.5 2 1 3 1.5 4 2 97 48.5 98 49 99 49.5 100 50 101 50.5 EOT ------------------------- -- :wq ^X^Cy^K^X^C^C^C^C |
|
From: Ico <gn...@ze...> - 2015-10-21 14:40:22
|
* On 2015-10-21 16:23:06 +0200, Marek W. Gutowski wrote:
> "%S" breaks at 60, not 100. You didn't read gnuplot's help, did you?
My apologies if I seem ignorant, but I did read all that before posting,
which is why I was using %s and not %S in the first place. Testing shows
that %S works well up to 99, and not 59 however. The documentation of
timefmt says about %S:
%S second, integer 0--60 on output, (double) on input
Which implies that output is limited from 0 to 60, but input is not.
> Anyway, the time format is tricky, I agree.
It seems, because I still can't get it right.
> Start your commands with
> gnuplot> set xdata time # this is concerns input data
> gnuplot> set format x "%H:%M:%S" # this is for ticks at plot's x axis,
> maybe "%M:%S" will suit you better?
> gnuplot> set timefmt "%s" # lower case, input data format
> Now you may check:
> gnuplot> show format
> gnuplot> show timefmt
> and, if satisfied, proceed with your "plot" command.
> I see a straight line, bingo!
Well, that's funny, I don't! The following snippet still gives me a
crooked line:
http://i.imgur.com/xaEOyPm.jpg
-------------------------
set xdata time
set format x "%M:%S"
set timefmt "%s"
show format
show timefmt
plot "-" using 1:2 with lp
1 0.5
2 1
3 1.5
4 2
5 2.5
6 3
EOT
---------------------------
Output of 'show format' and 'show timefmt'
tic format is:
x-axis: "%M:%S"
y-axis: "% g"
x2-axis: "% g"
y2-axis: "% g"
z-axis: "% g"
cb-axis: "% g"
r-axis: "% g"
read format for time on x axis is "%S"
read format for time on t axis is "%S"
read format for time on u axis is "%S"
--
:wq
^X^Cy^K^X^C^C^C^C
|
|
From: Ico <gn...@ze...> - 2015-10-21 16:55:16
|
* On 2015-10-21 18:14:49 +0200, Marek W. Gutowski wrote: > Well, as I can see, one of the formats is not the one intended: > "S" instead of "s" in timefmt, see your own message below. > My own result is attached. Note that this figure was zoomed > out (using CTRL-mouse wheel down); the raw result was > disappointing. The line was straight but x-tics were not all > different - some were repeated. Moreover, the points were > not distributed uniformly (!). Funny behaviour as well. > Maybe we are using incompatible versions of gnuplot? No, it seems we're not, my gnuplot is 4.6 patchlevel 6 > In summary: the timelike data are best graphed when both > input and output are in timelike format, made known to gnuplot > in advance. Otherwise gnuplot may get confused, just like in your case. > Therefore you have two choices: > 1. Modify your input data to be formatted similarly to 0:1 (0 minutes, 1 second), > or > 2. use seconds as units on x-axis, don't bother with time, time units may > be explained then in x-label (set xlabel "(s)" ) Clear. I've already moved to the first option for my case. Still, this is a workaround and not a true solution. Can the behaviour we see be considered a bug and should this be filed somewhere official? -- :wq ^X^Cy^K^X^C^C^C^C |
|
From: Ethan M. <eam...@gm...> - 2015-10-21 19:25:04
|
On Wed, Oct 21, 2015 at 2:42 AM, <gn...@ze...> wrote:
> Hi Gnuplot-info,
>
> I'm trying to plot data on a relative time scale starting at 0 the input
> is a column of seconds and a column of data.
>
> ---------------------------
> set xdata time
> set timefmt "%s"
>
> plot "-" using 1:2 with lp
> 0 0.0
> 1 0.5
> 2 1.0
> 3 1.5
> EOF
> ---------------------------
>
> can someone explain why I get these results:
I think you are confusing the format of the input data with the format
of the x-axis tics in the final plot. It looks like your input is
just a number (time in seconds I suppose), so no time format is
needed.
This answer is for gnuplot version 5.
Earlier versions had somewhat different options available for handling times.
1) If you want time-in-seconds for both input and output then there is
no need for any special handling, time formats, or any of that.
Seconds are seconds - just some number.
2) If the input is time-in-seconds but the output is some clock time
(hours:minutes:seconds) then you want the following. Notice there is
no "set xdata time".
set xtics time format "%H:%M:%S"
plot '-' using 1:2 with lp
3) If you want a relative time rather than a clock time, then you want
a different format that is new in gnuplot 5. This one will not wrap
at 24hrs and also allows for negative values of relative time. See
"help time_specifiers". Also see the 3rd plot in the demo
http://gnuplot.sourceforge.net/demo_5.0/timedat.html
set xtics time format "%tH:%tM:%tS"
plot '-' using 1:2 with lp
Ethan
|
|
From: Tait <gnu...@t4...> - 2015-10-21 23:44:43
|
> > --------------------------- > > set xdata time > > set timefmt "%s" > > > > plot "-" using 1:2 with lp > > 0 0.0 > > 1 0.5 > > 2 1.0 > > 3 1.5 > > EOF > > --------------------------- > > ... > This answer is for gnuplot version 5. > ... > 2) If the input is time-in-seconds but the output is some clock time > (hours:minutes:seconds) then you want the following. Notice there is > no "set xdata time". > > set xtics time format "%H:%M:%S" > plot '-' using 1:2 with lp There's nothing special about 0, 1, 2, 3... it could just as well be 1445469700 0.0 1445469701 0.5 1445469702 1.0 1445469703 1.5 Does this mean "set xdata time" is deprecated? Or only deprecated for the "%s" timefmt? I'm not sure I see why "timefmt '%s'" works without "set xdata", or "set xdata" works with e.g. "timefmt '%S'", but the particular combination of xdata and %s breaks. And I'm not sure it will be clear to other or new users, either. There must be some principle behind the behavior being what it is, but I don't see it. Can you explain more? |
|
From: Ethan A M. <eam...@gm...> - 2015-10-22 05:10:05
|
On Wednesday, 21 October 2015 11:44:30 PM Tait wrote: > > > --------------------------- > > > set xdata time > > > set timefmt "%s" > > > > > > plot "-" using 1:2 with lp > > > 0 0.0 > > > 1 0.5 > > > 2 1.0 > > > 3 1.5 > > > EOF > > > --------------------------- > > > > ... > > This answer is for gnuplot version 5. > > ... > > 2) If the input is time-in-seconds but the output is some clock time > > (hours:minutes:seconds) then you want the following. Notice there is > > no "set xdata time". > > > > set xtics time format "%H:%M:%S" > > plot '-' using 1:2 with lp > > There's nothing special about 0, 1, 2, 3... it could just as well be > 1445469700 0.0 > 1445469701 0.5 > 1445469702 1.0 > 1445469703 1.5 I agree there is some sort of bug with "%s". Right now I have no idea what the issue is, but since the same behaviour is observed in version 4.6.4 it is a bug that has been around for at least a couple of years. I notice that if you put decimal points after the values in the first data column then the bug isn't triggered. But the larger point is that the commands that are triggering the bug are not necessary in the first place. If you are reading in raw seconds you do not need a time format. > Does this mean "set xdata time" is deprecated? It is no longer necessary for most purposes, but so far as I know it still works as it did since gnuplot version 4.6.4 (I am seeing different output from gnuplot 4.6.3). > Or only deprecated > for the "%s" timefmt? I'm not sure I see why "timefmt '%s'" works > without "set xdata", or "set xdata" works with e.g. "timefmt '%S'", > but the particular combination of xdata and %s breaks. And I'm not > sure it will be clear to other or new users, either. There must be > some principle behind the behavior being what it is, but I don't > see it. Can you explain more? I'll try. Why the old commands were insufficient ====================================== - The time format present in a data file is a property of that file, not of some gnuplot axis. So having a global command like "set timefmt" is useless if you want to read from two files with different formats. - Requiring time to be associated with a particular output axis (e.g. "set xdata time") does not work if you are trying to read a time for some purpose other than an axis coordinate. What if you want to plot something like plot DAT using 1 : (time_in_column(3) > time_in_column(4) ? N : -N) The time values in question are neither x data nor y data. - Relative time values basically didn't work. Negative numbers were interpreted as some date prior to 1-Jan-1970 rather than as a value in seconds relative to time 0. Wrapping (e.g. seconds never exceed 60, hours never exceed 24, etc) may be undesirable. The version 5 syntax ==================== The preferred way to read time data on input is like this: fmt3 = "%m/%d/%y" fmt4 = "%Y %M %d" plot DATA using 1 : (timecolumn(3,fmt3) > timecolumn(4,fmt4) ? N : -N) This does not require that either the x or y axis is being used for time data, and allows different time formats for each column in each file if needed. For convenience if you omit the 2nd parameter to timecolumn() it will default to the current value of "set timefmt" set timefmt "%H:%M:%S" plot DATA using 1 : (timecolumn(3) > timecolumn(4) ? foo : baz) The deprecated "set xdata" command is not relevant in either case. The preferred way to set an output format is like this: set ytics time format "%H:%M:%S" Again the deprecated "set xdata" command is not relevant. The y value may come from a file, they may be calculated, or whatever. This just sets an output format. Version 5 also supports relative times (e.g. "%tH" format), and geographic coordinates "set xtics geo format "%D:%M:%S" for degrees/minutes/seconds wrapping at 360° rather than 24 hours and recognizing E/W formats for +/- values. Maybe some other stuff I'm not recalling at the moment. Backwards compatibility ======================= As you know, we always try to retain backwards compatibility as much as possible. The intent was that the older time commands like "set xdata time" still work, at least to the extent they ever did. Ethan |
|
From: Ethan A M. <eam...@gm...> - 2015-10-22 16:19:18
|
On Wednesday, 21 October 2015 10:09:57 PM Ethan A Merritt wrote: > On Wednesday, 21 October 2015 11:44:30 PM Tait wrote: > > > > --------------------------- > > > > set xdata time > > > > set timefmt "%s" > > > > > > > > plot "-" using 1:2 with lp > > > > 0 0.0 > > > > 1 0.5 > > > > 2 1.0 > > > > 3 1.5 > > > > EOF > > > > --------------------------- > > I agree there is some sort of bug with "%s". > Right now I have no idea what the issue is, but since the same > behaviour is observed in version 4.6.4 it is a bug that has > been around for at least a couple of years. > I notice that if you put decimal points after the values in the > first data column then the bug isn't triggered. Found it. Fixed in cvs for 5.0, 5.1, and (if anyone cares) 4.6 Ethan |
|
From: Tait <gnu...@t4...> - 2015-10-22 16:44:54
|
> I'll try. > > Why the old commands were insufficient > ====================================== > ... > The version 5 syntax > ==================== > ... Thanks for the explanation. Could this be copied into "help time/date" and maybe also a note added to "help set xdata" and "help time"? |
|
From: Ethan M. <eam...@gm...> - 2015-10-22 17:40:58
|
On Thu, Oct 22, 2015 at 9:44 AM, Tait <gnu...@t4...> wrote: >> I'll try. >> >> Why the old commands were insufficient >> ====================================== >> ... >> The version 5 syntax >> ==================== >> ... > > Thanks for the explanation. Could this be copied into "help > time/date" and maybe also a note added to "help set xdata" and "help > time"? I think all the information is in the documentation in various places, but maybe it needs better indexing. gnuplot> help timedata [...] Note: For backward compatibility with earlier gnuplot versions, the command `set xdata time` will implicitly also do `set xtics time`, and `set xdata` or `unset xdata` will implicitly reset to `set xtics numeric`. However you can change this with a later call to `set xtics`. See also the syntax summaries for "help set xtics", "help geographic", "help timefmt", and so on. It is true that there is no mention of new command options in "help set xdata". |