Discussion:
format x-axis as dates
Jev
2011-12-14 22:46:03 UTC
Permalink
I wonder if it is possible to plot a numeric vector against datetime
vector and adjust the axis labels accordingly. Could not find
something like this in examples or documentation. Any ideas?
Carlos Pascual
2011-12-15 11:44:37 UTC
Permalink
Post by Jev
I wonder if it is possible to plot a numeric vector against datetime
vector and adjust the axis labels accordingly. Could not find
something like this in examples or documentation. Any ideas?
I implemented this as a tool in an extension of guiqwt of my own project. It
is called TimeAxisTool.

The original code is in a bigger project with many dependencies
(https://www.tango-
controls.org/static/taurus/development/doc/html/devel/api/taurus/qt/qtgui/extra_guiqwt.html),
but I extracted the relevant parts and I put them in the attached files.

For testing, just run "python timeaxistool.py" and use the "Time Scale" option
from the context menu for changing the scale mode.
Note: When a scale is in "time" mode, the values are expected to be timestamps
and will be shown as properly edited date/times.

Note to Pierre (author of guiqwt): please feel free to add/adapt this code to
the official guiqwt if you think it is worth it. Also, apart from
DateTimeScaleEngine, the scales.py module contains two other useful scale
engines (DeltaTimeScaleEngine, FixedLabelsScaleEngine).

I hope this helps,

Carlos
--
+----------------------------------------------------+
Carlos Pascual Izarra
Scientific Software Coordinator
Computing Division
Cells / Alba Synchrotron [http:/www.cells.es]
Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
E-08290 Cerdanyola del Valles (Barcelona), Spain
E-mail: cpascual-***@public.gmane.org
Phone: +34 93 592 4428
+----------------------------------------------------+
Jev
2011-12-15 23:13:08 UTC
Permalink
@Carlos: Thank you for posting the code, it looks like a good starting
point.
Btw, zooming with the demo plot after applying y(t) causes exceptions
(timestamp out of range).

-Jev
Post by Jev
I wonder if it is possible to plot a numeric vector against datetime
vector and adjust the axis labels accordingly. Could not find
something like this in examples or documentation. Any ideas?
I implemented this as a tool in an extension of guiqwt of my own project.  It
is called TimeAxisTool.
The original code is in a bigger project with many dependencies
(https://www.tango-
controls.org/static/taurus/development/doc/html/devel/api/taurus/qt/qtgui/e xtra_guiqwt.html),
but I extracted the relevant parts and I put them in the attached files.
For testing, just run "python timeaxistool.py" and use the "Time Scale" option
from the context menu for changing the scale mode.
Note: When a scale is in "time" mode, the values are expected to be timestamps
and will be shown as properly edited date/times.
Note to Pierre (author of guiqwt):  please feel free to add/adapt this code to
the official guiqwt if you think it is worth it. Also, apart from
DateTimeScaleEngine, the scales.py module contains two other useful scale
engines (DeltaTimeScaleEngine, FixedLabelsScaleEngine).
I hope this helps,
Carlos
--
+----------------------------------------------------+
 Carlos Pascual Izarra
 Scientific Software Coordinator
 Computing Division
 Cells / Alba Synchrotron  [http:/www.cells.es]
 Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
 E-08290 Cerdanyola del Valles (Barcelona), Spain
 Phone: +34 93 592 4428
+----------------------------------------------------+
 timeaxistool.py
4KViewDownload
 scales.py
19KViewDownload
Carlos Pascual
2011-12-16 16:17:12 UTC
Permalink
Hi,
We are using this code quite often and I don't see the exceptions you mention.
Can you post some code and/or instructions on how to reproduce the problem?
Post by Jev
@Carlos: Thank you for posting the code, it looks like a good starting
point.
Btw, zooming with the demo plot after applying y(t) causes exceptions
(timestamp out of range).
-Jev
Post by Carlos Pascual
Post by Jev
I wonder if it is possible to plot a numeric vector against datetime
vector and adjust the axis labels accordingly. Could not find
something like this in examples or documentation. Any ideas?
I implemented this as a tool in an extension of guiqwt of my own project.
It is called TimeAxisTool.
The original code is in a bigger project with many dependencies
(https://www.tango-
controls.org/static/taurus/development/doc/html/devel/api/taurus/qt/qtgui
/e xtra_guiqwt.html), but I extracted the relevant parts and I put them
in the attached files.
For testing, just run "python timeaxistool.py" and use the "Time Scale"
option from the context menu for changing the scale mode.
Note: When a scale is in "time" mode, the values are expected to be
timestamps and will be shown as properly edited date/times.
Note to Pierre (author of guiqwt): please feel free to add/adapt this
code to the official guiqwt if you think it is worth it. Also, apart
from DateTimeScaleEngine, the scales.py module contains two other useful
scale engines (DeltaTimeScaleEngine, FixedLabelsScaleEngine).
I hope this helps,
Carlos
--
+----------------------------------------------------+
Carlos Pascual Izarra
Scientific Software Coordinator
Computing Division
Cells / Alba Synchrotron [http:/www.cells.es]
Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
E-08290 Cerdanyola del Valles (Barcelona), Spain
Phone: +34 93 592 4428
+----------------------------------------------------+
timeaxistool.py
4KViewDownload
scales.py
19KViewDownload
--
+----------------------------------------------------+
Carlos Pascual Izarra
Scientific Software Coordinator
Computing Division
Cells / Alba Synchrotron [http:/www.cells.es]
Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
E-08290 Cerdanyola del Valles (Barcelona), Spain
E-mail: cpascual-***@public.gmane.org
Phone: +34 93 592 4428
+----------------------------------------------------+
Jev
2011-12-19 20:17:13 UTC
Permalink
Well, after the default axis is formatted to datetime y(t) and you try
to zoom by clicking the right mouse button and moving it the following
happends:
Traceback (most recent call last):
File "C:\Users\jev\Documents\Development\tradingWithPython\cookbook
\scales.py", line 131, in divideScale
dt1=datetime.fromtimestamp(interval.minValue())
ValueError: timestamp out of range for platform localtime()/gmtime()
function
Post by Carlos Pascual
Hi,
We are using this code quite often and I don't see the exceptions you mention.
Can you post some code and/or instructions on how to reproduce the problem?
Post by Jev
@Carlos: Thank you for posting the code, it looks like a good starting
point.
Btw, zooming with the demo plot after applying y(t) causes exceptions
(timestamp out of range).
-Jev
Post by Carlos Pascual
Post by Jev
I wonder if it is possible to plot a numeric vector against datetime
vector and adjust the axis labels accordingly. Could not find
something like this in examples or documentation. Any ideas?
I implemented this as a tool in an extension of guiqwt of my own project.
 It is called TimeAxisTool.
The original code is in a bigger project with many dependencies
(https://www.tango-
controls.org/static/taurus/development/doc/html/devel/api/taurus/qt/qtgui
/e xtra_guiqwt.html), but I extracted the relevant parts and I put them
in the attached files.
For testing, just run "python timeaxistool.py" and use the "Time Scale"
option from the context menu for changing the scale mode.
Note: When a scale is in "time" mode, the values are expected to be
timestamps and will be shown as properly edited date/times.
Note to Pierre (author of guiqwt):  please feel free to add/adapt this
code to the official guiqwt if you think it is worth it. Also, apart
from DateTimeScaleEngine, the scales.py module contains two other useful
scale engines (DeltaTimeScaleEngine, FixedLabelsScaleEngine).
I hope this helps,
Carlos
--
+----------------------------------------------------+
 Carlos Pascual Izarra
 Scientific Software Coordinator
 Computing Division
 Cells / Alba Synchrotron  [http:/www.cells.es]
 Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
 E-08290 Cerdanyola del Valles (Barcelona), Spain
 Phone: +34 93 592 4428
+----------------------------------------------------+
 timeaxistool.py
4KViewDownload
 scales.py
19KViewDownload
--
+----------------------------------------------------+
 Carlos Pascual Izarra
 Scientific Software Coordinator
 Computing Division
 Cells / Alba Synchrotron  [http:/www.cells.es]
 Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
 E-08290 Cerdanyola del Valles (Barcelona), Spain
 Phone: +34 93 592 4428
+----------------------------------------------------+
Jev
2011-12-19 20:26:05 UTC
Permalink
...got it working after providing the right x-vector.
Thanks.
Post by Jev
Well, after the default axis is formatted to datetime y(t) and you try
to zoom by clicking the right mouse button and moving it the following
  File "C:\Users\jev\Documents\Development\tradingWithPython\cookbook
\scales.py", line 131, in divideScale
    dt1=datetime.fromtimestamp(interval.minValue())
ValueError: timestamp out of range for platform localtime()/gmtime()
function
Post by Carlos Pascual
Hi,
We are using this code quite often and I don't see the exceptions you mention.
Can you post some code and/or instructions on how to reproduce the problem?
Post by Jev
@Carlos: Thank you for posting the code, it looks like a good starting
point.
Btw, zooming with the demo plot after applying y(t) causes exceptions
(timestamp out of range).
-Jev
Post by Carlos Pascual
Post by Jev
I wonder if it is possible to plot a numeric vector against datetime
vector and adjust the axis labels accordingly. Could not find
something like this in examples or documentation. Any ideas?
I implemented this as a tool in an extension of guiqwt of my own project.
 It is called TimeAxisTool.
The original code is in a bigger project with many dependencies
(https://www.tango-
controls.org/static/taurus/development/doc/html/devel/api/taurus/qt/qtgui
/e xtra_guiqwt.html), but I extracted the relevant parts and I put them
in the attached files.
For testing, just run "python timeaxistool.py" and use the "Time Scale"
option from the context menu for changing the scale mode.
Note: When a scale is in "time" mode, the values are expected to be
timestamps and will be shown as properly edited date/times.
Note to Pierre (author of guiqwt):  please feel free to add/adapt this
code to the official guiqwt if you think it is worth it. Also, apart
from DateTimeScaleEngine, the scales.py module contains two other useful
scale engines (DeltaTimeScaleEngine, FixedLabelsScaleEngine).
I hope this helps,
Carlos
--
+----------------------------------------------------+
 Carlos Pascual Izarra
 Scientific Software Coordinator
 Computing Division
 Cells / Alba Synchrotron  [http:/www.cells.es]
 Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
 E-08290 Cerdanyola del Valles (Barcelona), Spain
 Phone: +34 93 592 4428
+----------------------------------------------------+
 timeaxistool.py
4KViewDownload
 scales.py
19KViewDownload
--
+----------------------------------------------------+
 Carlos Pascual Izarra
 Scientific Software Coordinator
 Computing Division
 Cells / Alba Synchrotron  [http:/www.cells.es]
 Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
 E-08290 Cerdanyola del Valles (Barcelona), Spain
 Phone: +34 93 592 4428
+----------------------------------------------------+
Jason Sexauer
2013-11-07 16:20:28 UTC
Permalink
Jev,

I know this is an old post, but I have the same problem you describe above
(the time axis shows up ok at first, but then when you click the
right-mouse button it drops its formatting and displays that error). Can
you clarify how you fixed this problem by "providing the right x-vector"?

Thanks!
Post by Jev
...got it working after providing the right x-vector.
Thanks.
Post by Jev
Well, after the default axis is formatted to datetime y(t) and you try
to zoom by clicking the right mouse button and moving it the following
File "C:\Users\jev\Documents\Development\tradingWithPython\cookbook
\scales.py", line 131, in divideScale
dt1=datetime.fromtimestamp(interval.minValue())
ValueError: timestamp out of range for platform localtime()/gmtime()
function
Post by Carlos Pascual
Hi,
We are using this code quite often and I don't see the exceptions you
mention.
Post by Jev
Post by Carlos Pascual
Can you post some code and/or instructions on how to reproduce the
problem?
Post by Jev
Post by Carlos Pascual
Post by Jev
@Carlos: Thank you for posting the code, it looks like a good
starting
Post by Jev
Post by Carlos Pascual
Post by Jev
point.
Btw, zooming with the demo plot after applying y(t) causes exceptions
(timestamp out of range).
-Jev
Post by Carlos Pascual
Post by Jev
I wonder if it is possible to plot a numeric vector against
datetime
Post by Jev
Post by Carlos Pascual
Post by Jev
Post by Carlos Pascual
Post by Jev
vector and adjust the axis labels accordingly. Could not find
something like this in examples or documentation. Any ideas?
I implemented this as a tool in an extension of guiqwt of my own
project.
Post by Jev
Post by Carlos Pascual
Post by Jev
Post by Carlos Pascual
It is called TimeAxisTool.
The original code is in a bigger project with many dependencies
(https://www.tango-
controls.org/static/taurus/development/doc/html/devel/api/taurus/qt/qtgui
Post by Jev
Post by Carlos Pascual
Post by Jev
Post by Carlos Pascual
/e xtra_guiqwt.html), but I extracted the relevant parts and I put
them
Post by Jev
Post by Carlos Pascual
Post by Jev
Post by Carlos Pascual
in the attached files.
For testing, just run "python timeaxistool.py" and use the "Time
Scale"
Post by Jev
Post by Carlos Pascual
Post by Jev
Post by Carlos Pascual
option from the context menu for changing the scale mode.
Note: When a scale is in "time" mode, the values are expected to be
timestamps and will be shown as properly edited date/times.
Note to Pierre (author of guiqwt): please feel free to add/adapt
this
Post by Jev
Post by Carlos Pascual
Post by Jev
Post by Carlos Pascual
code to the official guiqwt if you think it is worth it. Also,
apart
Post by Jev
Post by Carlos Pascual
Post by Jev
Post by Carlos Pascual
from DateTimeScaleEngine, the scales.py module contains two other
useful
Post by Jev
Post by Carlos Pascual
Post by Jev
Post by Carlos Pascual
scale engines (DeltaTimeScaleEngine, FixedLabelsScaleEngine).
I hope this helps,
Carlos
--
+----------------------------------------------------+
Carlos Pascual Izarra
Scientific Software Coordinator
Computing Division
Cells / Alba Synchrotron [http:/www.cells.es]
Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
E-08290 Cerdanyola del Valles (Barcelona), Spain
Phone: +34 93 592 4428
+----------------------------------------------------+
timeaxistool.py
4KViewDownload
scales.py
19KViewDownload
--
+----------------------------------------------------+
Carlos Pascual Izarra
Scientific Software Coordinator
Computing Division
Cells / Alba Synchrotron [http:/www.cells.es]
Carretera BP 1413 de Cerdanyola-Sant Cugat, Km. 3.3
E-08290 Cerdanyola del Valles (Barcelona), Spain
Phone: +34 93 592 4428
+----------------------------------------------------+
--
You received this message because you are subscribed to the Google Groups "guidata/guiqwt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guidata_guiqwt+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Jason Sexauer
2013-12-17 13:08:58 UTC
Permalink
I think I figured this out. There is a bug in the create_action_menu
routine:

The convention in the program is to use a tuple order of (x,y) but there
you originally had it as (y,x) (which matches the way you named the
functions). Here is the correction (notice the order of the True/False is
different for y_t and t_x)

self.scale_menu = {(False, False): y_x, (True, False): y_t,
(False, True): t_x, (True, True): t_t}
I wonder if it is possible to plot a numeric vector against datetime
vector and adjust the axis labels accordingly. Could not find
something like this in examples or documentation. Any ideas?
--
You received this message because you are subscribed to the Google Groups "guidata/guiqwt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guidata_guiqwt+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...