Quantcast

Time format data as a string?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Time format data as a string?

Daniel J Sebald
I just used the time format in a plot.  It's nice, incorporating the
date and time and all.  So thank you to whomever.

It did take me a bit to figure out though why something like this failed:

   set timefmt "%m/%d/%y %H:%M"
   plot "data" using 1:2

with data something like

03/03/16 11:30 23.5
03/03/16 11:45 24.8
...

It's because the datafile.c reading routine recognizes that first space
as a delimiter such that field ':2' is actually 11 in both cases shown.
  That's fine, as the following works:

   plot "data" using 1:3

and the documentation gives proper examples and all, if not explicitly
stating.

However, it's a bit of a mental juxtaposition because the person
scripting the code is thinking of the "03/03/16 11:30" as the "first"
entry.  Now, gnuplot has string inputs, such as in energy_circles.dat of
the demo subdirectory.  So, I'm wondering if the the date/time data
entry could also accept a datafile string.  It shouldn't be too much of
a C-code alteration.  For example, this might be the equivalent to the
above:

   plot "data" using 1:2

with data

"03/03/16 11:30" 23.5
"03/03/16 11:45" 24.8
...

I tried that, and gnuplot doesn't allow it (no surprise, as it isn't
documented to do so).  The way I see it, the user might be more inclined
to think of date/time data in that fashion.

Dan

------------------------------------------------------------------------------
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Time format data as a string?

Plotter-2
On 19/11/16 04:06, Daniel J Sebald wrote:

> I just used the time format in a plot.  It's nice, incorporating the
> date and time and all.  So thank you to whomever.
>
> It did take me a bit to figure out though why something like this failed:
>
>    set timefmt "%m/%d/%y %H:%M"
>    plot "data" using 1:2
>
> with data something like
>
> 03/03/16 11:30 23.5
> 03/03/16 11:45 24.8
> ...
>
> It's because the datafile.c reading routine recognizes that first space
> as a delimiter such that field ':2' is actually 11 in both cases shown.
>   That's fine, as the following works:
>
>    plot "data" using 1:3
>
> and the documentation gives proper examples and all, if not explicitly
> stating.

I think this should be explicitly documented.

I came up against this a while back and sussed it just by suck and see.

This solution does work quite well but is actually a hack / workaround
since it concatenates  both col 1 and col 2 to be col 1 but still calls
col 3 , col 3.

This is not intuitive and breaks the definitions of what are regarded as
separate input columns. Thus it should be documented explicitly rather
than just being included in an example.

Peter.



>
> However, it's a bit of a mental juxtaposition because the person
> scripting the code is thinking of the "03/03/16 11:30" as the "first"
> entry.  Now, gnuplot has string inputs, such as in energy_circles.dat of
> the demo subdirectory.  So, I'm wondering if the the date/time data
> entry could also accept a datafile string.  It shouldn't be too much of
> a C-code alteration.  For example, this might be the equivalent to the
> above:
>
>    plot "data" using 1:2
>
> with data
>
> "03/03/16 11:30" 23.5
> "03/03/16 11:45" 24.8
> ...
>
> I tried that, and gnuplot doesn't allow it (no surprise, as it isn't
> documented to do so).  The way I see it, the user might be more inclined
> to think of date/time data in that fashion.
>
> Dan
>
> ------------------------------------------------------------------------------
> _______________________________________________
> gnuplot-beta mailing list
> [hidden email]
> Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
>


------------------------------------------------------------------------------
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Time format data as a string?

Daniel J Sebald
In reply to this post by Daniel J Sebald
On 11/18/2016 10:06 PM, Daniel J Sebald wrote:

> I just used the time format in a plot.  It's nice, incorporating the
> date and time and all.  So thank you to whomever.
>
> It did take me a bit to figure out though why something like this failed:
>
>     set timefmt "%m/%d/%y %H:%M"
>     plot "data" using 1:2
>
> with data something like
>
> 03/03/16 11:30 23.5
> 03/03/16 11:45 24.8
> ...
>
> It's because the datafile.c reading routine recognizes that first space
> as a delimiter such that field ':2' is actually 11 in both cases shown.
>    That's fine, as the following works:
>
>     plot "data" using 1:3
>
> and the documentation gives proper examples and all, if not explicitly
> stating.
>
> However, it's a bit of a mental juxtaposition because the person
> scripting the code is thinking of the "03/03/16 11:30" as the "first"
> entry.  Now, gnuplot has string inputs, such as in energy_circles.dat of
> the demo subdirectory.  So, I'm wondering if the the date/time data
> entry could also accept a datafile string.  It shouldn't be too much of
> a C-code alteration.  For example, this might be the equivalent to the
> above:
>
>     plot "data" using 1:2
>
> with data
>
> "03/03/16 11:30" 23.5
> "03/03/16 11:45" 24.8
> ...
>
> I tried that, and gnuplot doesn't allow it (no surprise, as it isn't
> documented to do so).  The way I see it, the user might be more inclined
> to think of date/time data in that fashion.


The documentation says:

  In all cases, the numbers of each record of a data file must be separated
  by white space (one or more blanks or tabs) unless a format specifier is
  provided by the `using` option. This white space divides each record into
  columns. 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

Thinking more general, that begs the question as to why gnuplot couldn't
accept numbers within a string:

  "1.0""second column""3.0"

or even CSV format:

  1.0,second column,3.0

Not that I'm really keen on having that, but it may not be a far step
handling those formats.

Dan

------------------------------------------------------------------------------
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Time format data as a string?

sfeam
In reply to this post by Daniel J Sebald
On Friday, 18 November, 2016 22:06:54 Daniel J Sebald wrote:

> I just used the time format in a plot.  It's nice, incorporating the
> date and time and all.  So thank you to whomever.
>
> It did take me a bit to figure out though why something like this failed:
>
>    set timefmt "%m/%d/%y %H:%M"
>    plot "data" using 1:2
>
> with data something like
>
> 03/03/16 11:30 23.5
> 03/03/16 11:45 24.8
> ...
>
> It's because the datafile.c reading routine recognizes that first space
> as a delimiter such that field ':2' is actually 11 in both cases shown.
>   That's fine, as the following works:
>
>    plot "data" using 1:3
>
> and the documentation gives proper examples and all, if not explicitly
> stating.
>
> However, it's a bit of a mental juxtaposition because the person
> scripting the code is thinking of the "03/03/16 11:30" as the "first"
> entry.  Now, gnuplot has string inputs, such as in energy_circles.dat of
> the demo subdirectory.  So, I'm wondering if the the date/time data
> entry could also accept a datafile string.  It shouldn't be too much of
> a C-code alteration.  For example, this might be the equivalent to the
> above:
>
>    plot "data" using 1:2
>
> with data
>
> "03/03/16 11:30" 23.5
> "03/03/16 11:45" 24.8
> ...
>
> I tried that, and gnuplot doesn't allow it

Gnuplot does allow it.
Your test commands and data are plotted correctly so long as you
tell gnuplot that it is wrapped in a string:

   plot "data" using (strcol(1)):2

where strcol(N) is shorthand for stringcolumn(N)

        Ethan

------------------------------------------------------------------------------
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Time format data as a string?

sfeam
In reply to this post by Daniel J Sebald
On Saturday, 19 November, 2016 15:43:38 Daniel J Sebald wrote:
 

>
> The documentation says:
>
>   In all cases, the numbers of each record of a data file must be separated
>   by white space (one or more blanks or tabs) unless a format specifier is
>   provided by the `using` option. This white space divides each record into
>   columns. 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
>
> Thinking more general, that begs the question as to why gnuplot couldn't
> accept numbers within a string:
>
>   "1.0""second column""3.0"
>
> or even CSV format:
>
>   1.0,second column,3.0
>
> Not that I'm really keen on having that, but it may not be a far step
> handling those formats.

Gnuplot has accepted all of these input variants since they were introduced
in version 4.0 (2004).  Plotting from *.csv files is very common.
The relevant command is

   set datafile seperator

        - Ethan

------------------------------------------------------------------------------
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Time format data as a string?

Daniel J Sebald
In reply to this post by sfeam
On 11/21/2016 12:12 PM, Ethan A Merritt wrote:

> On Friday, 18 November, 2016 22:06:54 Daniel J Sebald wrote:
>> I just used the time format in a plot.  It's nice, incorporating the
>> date and time and all.  So thank you to whomever.
>>
>> It did take me a bit to figure out though why something like this failed:
>>
>>     set timefmt "%m/%d/%y %H:%M"
>>     plot "data" using 1:2
>>
>> with data something like
>>
>> 03/03/16 11:30 23.5
>> 03/03/16 11:45 24.8
>> ...
>>
>> It's because the datafile.c reading routine recognizes that first space
>> as a delimiter such that field ':2' is actually 11 in both cases shown.
>>    That's fine, as the following works:
>>
>>     plot "data" using 1:3
>>
>> and the documentation gives proper examples and all, if not explicitly
>> stating.
>>
>> However, it's a bit of a mental juxtaposition because the person
>> scripting the code is thinking of the "03/03/16 11:30" as the "first"
>> entry.  Now, gnuplot has string inputs, such as in energy_circles.dat of
>> the demo subdirectory.  So, I'm wondering if the the date/time data
>> entry could also accept a datafile string.  It shouldn't be too much of
>> a C-code alteration.  For example, this might be the equivalent to the
>> above:
>>
>>     plot "data" using 1:2
>>
>> with data
>>
>> "03/03/16 11:30" 23.5
>> "03/03/16 11:45" 24.8
>> ...
>>
>> I tried that, and gnuplot doesn't allow it
>
> Gnuplot does allow it.
> Your test commands and data are plotted correctly so long as you
> tell gnuplot that it is wrapped in a string:
>
>     plot "data" using (strcol(1)):2
>
> where strcol(N) is shorthand for stringcolumn(N)
>
> Ethan

I did try this the other day when I was busy working on some code.  It
does work, thanks.  I think this would be a good example to include as
well, simply because it seems a more natural way to think of things for
computer users, i.e., the two columns and also that a date/time field
would be thought of as a string.

Dan

------------------------------------------------------------------------------
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Time format data as a string?

Daniel J Sebald
In reply to this post by sfeam
On 11/21/2016 12:18 PM, Ethan A Merritt wrote:

> On Saturday, 19 November, 2016 15:43:38 Daniel J Sebald wrote:
>
>>
>> The documentation says:
>>
>>    In all cases, the numbers of each record of a data file must be separated
>>    by white space (one or more blanks or tabs) unless a format specifier is
>>    provided by the `using` option. This white space divides each record into
>>    columns. 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
>>
>> Thinking more general, that begs the question as to why gnuplot couldn't
>> accept numbers within a string:
>>
>>    "1.0""second column""3.0"
>>
>> or even CSV format:
>>
>>    1.0,second column,3.0
>>
>> Not that I'm really keen on having that, but it may not be a far step
>> handling those formats.
>
> Gnuplot has accepted all of these input variants since they were introduced
> in version 4.0 (2004).  Plotting from *.csv files is very common.
> The relevant command is
>
>     set datafile seperator
>
> - Ethan

I kind of remembered that, but couldn't think of the word.  I kept
trying "help delimiter".

Are people open to fine-tuning tab-completion?  All it seems to do is
select from the current directory's file list, but often that doesn't
make sense given the context and often leads to having to hold down the
backspace to erase a lengthy name.  For example, more context would be
good, such as "help im<tab-complete>" would give a list of options
similar to:

gnuplot> help im
Ambiguous request 'im'; possible matches:
        imag
        image
        import
        impulses

File names have to be in quotes, so only when the line is in an open
quote, e.g.,

plot "dat<tab-complete>

should a list of files appear as options.

Dan

------------------------------------------------------------------------------
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Loading...