Plot only relevant subsets of datetime-range?

95 views
Skip to first unread message

mks

unread,
Aug 17, 2020, 7:50:15 PM8/17/20
to pyqtgraph
Hello,

I've been wondering if it is possible to exclude subranges of datetimes, where there is no data? For example, when plotting financial data, markets are closed on weekends, so a continuous datetime axis will have gaps on Sundays and Saturdays (among other periods when there is no trading):
Screenshot_20200818_014602.png

Is it possible to exclude these gaps?

Thanks,
mks

Dennis Jensen

unread,
Aug 17, 2020, 8:45:55 PM8/17/20
to pyqt...@googlegroups.com
Yes you have full control of the data you supply to a graph of course the settings to do that might be rather tricky --- as such it might just be easiest to flat line it during those periods rather than try to exclude them

Virus-free. www.avast.com

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/e32a4a25-22c1-44e8-af2f-992abab6acban%40googlegroups.com.

Carlos Pascual-Izarra

unread,
Aug 18, 2020, 3:10:53 AM8/18/20
to pyqt...@googlegroups.com

I don't see how this can be accomplished solely by controlling the data. I think that it would require at least some hacking with the AxisItem class... and I myself would not know how...

In any case, certainly linking the flattening workaround might be the easiest.


On 8/18/20 2:45 AM, Dennis Jensen wrote:
Yes you have full control of the data you supply to a graph of course the settings to do that might be rather tricky --- as such it might just be easiest to flat line it during those periods rather than try to exclude them

Virus-free. www.avast.com

On Mon, Aug 17, 2020 at 6:50 PM mks <dear...@gmail.com> wrote:
Hello,

I've been wondering if it is possible to exclude subranges of datetimes, where there is no data? For example, when plotting financial data, markets are closed on weekends, so a continuous datetime axis will have gaps on Sundays and Saturdays (among other periods when there is no trading):
Screenshot_20200818_014602.png

Is it possible to exclude these gaps?

Thanks,
mks
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/e32a4a25-22c1-44e8-af2f-992abab6acban%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/CAJnEJx0mwN41n4nLXC9xpeP5dW_7fbmNtna0XKWxfNx8qE1ShA%40mail.gmail.com.
-- 
+----------------------------------------------------+
 Carlos Pascual Izarra
 Scientific Software Coordinator
 Computing Division
 ALBA Synchrotron  [http://www.albasynchrotron.es]
 Carrer de la Llum 2-26
 E-08290 Cerdanyola del Valles (Barcelona), Spain
 E-mail: cpas...@cells.es
 Phone: +34 93 592 4428
+----------------------------------------------------+

azpa...@gmail.com

unread,
Aug 18, 2020, 7:28:01 AM8/18/20
to pyqtgraph
Hi,
i think the easiest is to treat them as multiple plots. You can look at the examples- the one called basic plotting. The multiple curves would work for your case.

Mikołaj Śnioch

unread,
Aug 18, 2020, 10:40:17 AM8/18/20
to pyqt...@googlegroups.com
Thanks everyone for sharing your thoughts. I agree that this cannot be simply done by controlling data - it seems that by default axis data is assumed to be continuous, which will produce visual gaps on the chart if actual data is not continuous. Creating separate plots and placing them side by side with no margin would be ok for a static plot, however I am using these dynamically, so that won't work unfortunately. Unless I am missing something of course. By "using dynamically" I mean that I am panning/zoomng/scrolling the data a lot, adding new data sets on the same plot etc.

After an initial look it seems to me that it's not an Axis but the Viewbox that controls value ranges. If I understand correctly, the AxisItem controls presentation, not the underlying axis data. I can't say I am too familiar with how Viewbox works yet, but it seems to be built around an assumption that values are continuous in either linear or log fashion. There are numerous places in Viewbox code where xrange/xlimit is used, which suggests to me that whatever is within range/limits must be continuous (or is assumed to be).

I will continue to look into this, any tips are welcome.

Thank you,
mks

You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/z2FXYJw5hck/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/9c10f86e-28cf-4622-9f45-41f4ec469037n%40googlegroups.com.

mks

unread,
Aug 18, 2020, 10:51:58 AM8/18/20
to pyqtgraph
I gave it some more thought and I have to take back what I said about controlling data - actually, that may be the easiest way to go about it. Not the nicest, as it would require messing with timestamps, but perhaps the easiest.

The solution would require creating my own timestamp transformation that would be used to shift data in time and to adjust the AxisItem. For example - if I know that Saturday is empty, I will move data from Monday to Saturday (by subtracting two days from timestamps) and have the AxisItem pretend that Saturday data is Monday data. If applied to gaps that are regular, it could be a vector of cumulative offsets applied to the vector of timestamps.

Not sure it's the best way to go, but at least it's something I can try out in a reasonable amount of time.

Edmondo Giovannozzi

unread,
Aug 18, 2020, 11:06:37 AM8/18/20
to pyqtgraph
You may try to put NaNs on Saturdays an Sundays, then  use connect='finite' in the setData method.
Reply all
Reply to author
Forward
0 new messages