Simple Time Formatted Plot Problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Simple Time Formatted Plot Problem

Fritz Sonnichsen
I have played with this for a while. I have been able to plot time
series data in the past but now something has gone wrong. I have
distilled the problem into the short stretch of code below. The data
plots without specifying the time axis, but when I add the time
formatted axis it look find but the data does not appear.
   Any ideas?
Thanks
Fritz
======================= CODE ===========================
1;
clear all
fflush(stdin);

xtme=["12:20:39";"12:20:41";"12:20:42";"12:20:43";"12:20:44"];
xT=[    1      ;2       ;3       ;4       ;5];


plot(xT)
figure
timeFormat='HH:MM:SS';
xdatenum=datenum(xtme,timeFormat); %days from January 0, 0000
xlen = length(xtme);
plot(xdatenum,xT,'color','r');
datetick('x',timeFormat,'keepticks')
axis([0 xlen 0  10])
     return



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Simple Time Formatted Plot Problem

marco atzeri-2
On 02/03/2018 17:14, Fritz Sonnichsen wrote:

> I have played with this for a while. I have been able to plot time
> series data in the past but now something has gone wrong. I have
> distilled the problem into the short stretch of code below. The data
> plots without specifying the time axis, but when I add the time
> formatted axis it look find but the data does not appear.
>    Any ideas?
> Thanks
> Fritz
> ======================= CODE ===========================
> 1;
> clear all
> fflush(stdin);
>
> xtme=["12:20:39";"12:20:41";"12:20:42";"12:20:43";"12:20:44"];
> xT=[    1      ;2       ;3       ;4       ;5];
>
>
> plot(xT)
> figure
> timeFormat='HH:MM:SS';
> xdatenum=datenum(xtme,timeFormat); %days from January 0, 0000
> xlen = length(xtme);
> plot(xdatenum,xT,'color','r');
> datetick('x',timeFormat,'keepticks')
> axis([0 xlen 0  10])
>      return
>

the axis is out of the data range

xdatenum =

    7.3706e+05




-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Simple Time Formatted Plot Problem

Fritz Sonnichsen
Thanks-

Replacing the last few lines with the ones below does not work either:
dmin= min(xdatenum)
dmax= max(xdatenum)
axis([dmin dmax 0  10])

Nor does removing the axis statement altogether
Fritz


On 3/2/2018 11:32 AM, Marco Atzeri wrote:

> On 02/03/2018 17:14, Fritz Sonnichsen wrote:
>> I have played with this for a while. I have been able to plot time
>> series data in the past but now something has gone wrong. I have
>> distilled the problem into the short stretch of code below. The data
>> plots without specifying the time axis, but when I add the time
>> formatted axis it look find but the data does not appear.
>>    Any ideas?
>> Thanks
>> Fritz
>> ======================= CODE ===========================
>> 1;
>> clear all
>> fflush(stdin);
>>
>> xtme=["12:20:39";"12:20:41";"12:20:42";"12:20:43";"12:20:44"];
>> xT=[    1      ;2       ;3       ;4       ;5];
>>
>>
>> plot(xT)
>> figure
>> timeFormat='HH:MM:SS';
>> xdatenum=datenum(xtme,timeFormat); %days from January 0, 0000
>> xlen = length(xtme);
>> plot(xdatenum,xT,'color','r');
>> datetick('x',timeFormat,'keepticks')
>> axis([0 xlen 0  10])
>>      return
>>
>
> the axis is out of the data range
>
> xdatenum =
>
>    7.3706e+05
>
>
>
>
> -----------------------------------------
> Join us March 12-15 at CERN near Geneva
> Switzerland for OctConf 2018.  More info:
> https://wiki.octave.org/OctConf_2018
> -----------------------------------------



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Simple Time Formatted Plot Problem

marco atzeri-2
On 02/03/2018 18:05, Fritz Sonnichsen wrote:

> Thanks-
>
> Replacing the last few lines with the ones below does not work either:
> dmin= min(xdatenum)
> dmax= max(xdatenum)
> axis([dmin dmax 0  10])
>
> Nor does removing the axis statement altogether
> Fritz
>

without the axis, it works for me.
Use the "graphics_toolkit gnuplot" as fltk has problem on
numbers too near and large (due to resolution on float)


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Simple Time Formatted Plot Problem

Fritz Sonnichsen
adding: graphics_toolkit ("gnuplot");
and removing the axis statements produced a plot with no line. (code
below) The range on the plot was from -21475.2 thru -21474.4

So do all my time-formatting statements need to be re-written for some
type of gnuplot routines?
thanks
Fritz

============================================================
1;
clear all
fflush(stdin);
graphics_toolkit ("gnuplot");

xtme=["12:20:39";"12:20:41";"12:20:42";"12:20:43";"12:20:44"];
xT=[    1      ;2       ;3       ;4       ;5];
timeFormat='HH:MM:SS';
xdatenum=datenum(xtme,timeFormat); %days from January 0, 0000
plot(xdatenum,xT,'color','r');
datetick('x',timeFormat,'keepticks')
=======================================================
On 3/2/2018 12:14 PM, Marco Atzeri wrote:

> On 02/03/2018 18:05, Fritz Sonnichsen wrote:
>> Thanks-
>>
>> Replacing the last few lines with the ones below does not work either:
>> dmin= min(xdatenum)
>> dmax= max(xdatenum)
>> axis([dmin dmax 0  10])
>>
>> Nor does removing the axis statement altogether
>> Fritz
>>
>
> without the axis, it works for me.
> Use the "graphics_toolkit gnuplot" as fltk has problem on
> numbers too near and large (due to resolution on float)
>
>
> -----------------------------------------
> Join us March 12-15 at CERN near Geneva
> Switzerland for OctConf 2018.  More info:
> https://wiki.octave.org/OctConf_2018
> -----------------------------------------



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Simple Time Formatted Plot Problem

Mike Miller-4
In reply to this post by marco atzeri-2
On Fri, Mar 02, 2018 at 18:14:44 +0100, Marco Atzeri wrote:
> without the axis, it works for me.
> Use the "graphics_toolkit gnuplot" as fltk has problem on
> numbers too near and large (due to resolution on float)

Or subtract away the irrelevant date part of the datenum values

    xdatenum = xdatenum - datenum ([2018, 1, 1, 0, 0, 0]);

I thought we had a FAQ entry about this, but I don't see one.

--
mike


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Simple Time Formatted Plot Problem

Fritz Sonnichsen
Mike. That worked. Still curious why Marco's approach works for him but not on my machine. I am working on a win machine today-maybe something about the way it handles floating point etc.
   I will use your approach-it would be nice if the Octave team would incorporate this into their code at some point so it is less "patched together". I would expect plotting time series is pretty common and something a little more streamlined would be nice. I vaguely recall that Matlab was similarly afflicted.

Thanks again both of you for your help!
Fritz

On 3/2/2018 1:02 PM, Mike Miller wrote:
On Fri, Mar 02, 2018 at 18:14:44 +0100, Marco Atzeri wrote:
without the axis, it works for me.
Use the "graphics_toolkit gnuplot" as fltk has problem on
numbers too near and large (due to resolution on float)
Or subtract away the irrelevant date part of the datenum values

    xdatenum = xdatenum - datenum ([2018, 1, 1, 0, 0, 0]);

I thought we had a FAQ entry about this, but I don't see one.



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Simple Time Formatted Plot Problem

Ian McCallion
Another way may be to let octave chose the axis ranges. Not at computer, but I think you need axis(-inf inf 0 10); 

Cheers... Ian

On 3 Mar 2018 00:57, "Fritz Sonnichsen" <[hidden email]> wrote:
Mike. That worked. Still curious why Marco's approach works for him but not on my machine. I am working on a win machine today-maybe something about the way it handles floating point etc.
   I will use your approach-it would be nice if the Octave team would incorporate this into their code at some point so it is less "patched together". I would expect plotting time series is pretty common and something a little more streamlined would be nice. I vaguely recall that Matlab was similarly afflicted.

Thanks again both of you for your help!
Fritz

On 3/2/2018 1:02 PM, Mike Miller wrote:
On Fri, Mar 02, 2018 at 18:14:44 +0100, Marco Atzeri wrote:
without the axis, it works for me.
Use the "graphics_toolkit gnuplot" as fltk has problem on
numbers too near and large (due to resolution on float)
Or subtract away the irrelevant date part of the datenum values

    xdatenum = xdatenum - datenum ([2018, 1, 1, 0, 0, 0]);

I thought we had a FAQ entry about this, but I don't see one.



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Simple Time Formatted Plot Problem

Andreas Weber-6
In reply to this post by Fritz Sonnichsen
Am 02.03.2018 um 17:14 schrieb Fritz Sonnichsen:

> I have played with this for a while. I have been able to plot time
> series data in the past but now something has gone wrong. I have
> distilled the problem into the short stretch of code below. The data
> plots without specifying the time axis, but when I add the time
> formatted axis it look find but the data does not appear.
>   Any ideas?
> Thanks
> Fritz
> ======================= CODE ===========================
> 1;
> clear all
> fflush(stdin);
>
> xtme=["12:20:39";"12:20:41";"12:20:42";"12:20:43";"12:20:44"];
> xT=[    1      ;2       ;3       ;4       ;5];
>
>
> plot(xT)
> figure
> timeFormat='HH:MM:SS';
> xdatenum=datenum(xtme,timeFormat); %days from January 0, 0000
> xlen = length(xtme);
> plot(xdatenum,xT,'color','r');
> datetick('x',timeFormat,'keepticks')
> axis([0 xlen 0  10])
>     return

I normally set the timeticks manually:

clear all

xtme=["12:20:39";"12:20:41";"12:20:42";"12:20:43";"12:20:44"];
xT=[    1      ;2       ;3       ;4       ;5];

timeFormat='HH:MM:SS';
xdatenum=datenum(xtme,timeFormat); %days from January 0, 0000

plot (xT, 'color', 'r');

## make sure xticks are valid indexes
set (gca, "xtick", round (get (gca, "xtick")))

## set xticklabels manually
set (gca, "xticklabel", datestr (xdatenum, timeFormat))



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Simple Time Formatted Plot Problem

Fritz Sonnichsen
In reply to this post by Ian McCallion
Thanks Ian.
  the syntax is close but actually must contain a vector:   axis([-inf inf 0 10]);
This works nicely---a good tip

fritz

On 3/2/2018 8:25 PM, Ian McCallion wrote:
Another way may be to let octave chose the axis ranges. Not at computer, but I think you need axis(-inf inf 0 10); 

Cheers... Ian

On 3 Mar 2018 00:57, "Fritz Sonnichsen" <[hidden email]> wrote:
Mike. That worked. Still curious why Marco's approach works for him but not on my machine. I am working on a win machine today-maybe something about the way it handles floating point etc.
   I will use your approach-it would be nice if the Octave team would incorporate this into their code at some point so it is less "patched together". I would expect plotting time series is pretty common and something a little more streamlined would be nice. I vaguely recall that Matlab was similarly afflicted.

Thanks again both of you for your help!
Fritz

On 3/2/2018 1:02 PM, Mike Miller wrote:
On Fri, Mar 02, 2018 at 18:14:44 +0100, Marco Atzeri wrote:
without the axis, it works for me.
Use the "graphics_toolkit gnuplot" as fltk has problem on
numbers too near and large (due to resolution on float)
Or subtract away the irrelevant date part of the datenum values

    xdatenum = xdatenum - datenum ([2018, 1, 1, 0, 0, 0]);

I thought we had a FAQ entry about this, but I don't see one.



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------




-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------