OHLC chart

884 views
Skip to first unread message

usir

unread,
Jul 10, 2012, 10:00:04 PM7/10/12
to pyqt...@googlegroups.com
I'm still evaluating pyqtgraph but I'm very impressed by the overall capabilities and performance. Congrats to the developers.

I have a few question:
1. is there support to OHLC [1] charts? Specially candle sticks
2. is there support for data consolidation? I mean, depending on the zoom level, values would be aggregated in a way the chart doesn't get polluted and still gives meaningful data. Say I have a set of values for a certain year. Looking at a day period I'd like to see each tick, but looking at a year period I'd like to see the month's average
3. is there any kind of interpolation? Specially spline interpolation. Given a set of values it would be useful to see a smooth curve.

Luke Campagnola

unread,
Jul 11, 2012, 2:16:46 AM7/11/12
to pyqt...@googlegroups.com
On Tue, Jul 10, 2012 at 10:00 PM, usir <rafa...@gmail.com> wrote:
I have a few question:

The answer to all three questions is 'no', however all three are quite easy to implement if you're familiar with Qt. Read on..
 
1. is there support to OHLC [1] charts? Specially candle sticks

The attached file implements a simple candlestick graphics item in about 20 lines of code. I think I'll probably include that as one of the examples in pyqtgraph..
 
2. is there support for data consolidation? I mean, depending on the zoom level, values would be aggregated in a way the chart doesn't get polluted and still gives meaningful data. Say I have a set of values for a certain year. Looking at a day period I'd like to see each tick, but looking at a year period I'd like to see the month's average

To implement this, I would:
  1) Generate multiple QPicture objects, one for each level-of-detail you want
  2) Modify CandlestickItem.paint() to check the visible time range:
            tMin, tMax = self.getViewBox().viewRange()[0]
      and then decide which picture to draw based on the width of the range.
 
3. is there any kind of interpolation? Specially spline interpolation. Given a set of values it would be useful to see a smooth curve.

I can think of a couple easy ways to do this. First is to use scipy to interpolate the data:
    import scipy.interpolate as interp
    spline = interp.UnivariateSpline(xvals, yvals)
    smooth = spline(dense_xvals)
    pg.plot(dense_xvals, smooth)

Second is to use QPainterPath.cubicTo(...) to generate an actual cubic spline path and add it to a plot with QGraphicsPathItem (but you'd have to work out the knot locations yourself for that). 

Luke

 
customGraphicsItem.py
Reply all
Reply to author
Forward
0 new messages