Module audian.timeplot

PlotItem for displaying any data as a function of time.

Classes

class TimePlot (aspec, channel, browser, xwidth, ylabel='')

GraphicsWidget implementing a standard 2D plotting area with axes.

Bases: :class:GraphicsWidget <pyqtgraph.GraphicsWidget>

This class provides the ViewBox-plus-axes that appear when using :func:pg.plot() <pyqtgraph.plot>, :class:PlotWidget <pyqtgraph.PlotWidget>, and :func:GraphicsLayout.addPlot() <pyqtgraph.GraphicsLayout.addPlot>.

It's main functionality is:

  • Manage placement of ViewBox, AxisItems, and LabelItems
  • Create and manage a list of PlotDataItems displayed inside the ViewBox
  • Implement a context menu with commonly used display and analysis options

Use :func:plot() <pyqtgraph.PlotItem.plot> to create a new PlotDataItem and add it to the view. Use :func:addItem() <pyqtgraph.PlotItem.addItem> to add any QGraphicsItem to the view.

This class wraps several methods from its internal ViewBox: - :func:setXRange <pyqtgraph.ViewBox.setXRange> - :func:setYRange <pyqtgraph.ViewBox.setYRange> - :func:setRange <pyqtgraph.ViewBox.setRange> - :func:autoRange <pyqtgraph.ViewBox.autoRange> - :func:setDefaultPadding <pyqtgraph.ViewBox.setDefaultPadding> - :func:setXLink <pyqtgraph.ViewBox.setXLink> - :func:setYLink <pyqtgraph.ViewBox.setYLink> - :func:setAutoPan <pyqtgraph.ViewBox.setAutoPan> - :func:setAutoVisible <pyqtgraph.ViewBox.setAutoVisible> - :func:setLimits <pyqtgraph.ViewBox.setLimits> - :func:viewRect <pyqtgraph.ViewBox.viewRect> - :func:viewRange <pyqtgraph.ViewBox.viewRange> - :func:setMouseEnabled <pyqtgraph.ViewBox.setMouseEnabled> - :func:enableAutoRange <pyqtgraph.ViewBox.enableAutoRange> - :func:disableAutoRange <pyqtgraph.ViewBox.disableAutoRange> - :func:setAspectLocked <pyqtgraph.ViewBox.setAspectLocked> - :func:invertY <pyqtgraph.ViewBox.invertY> - :func:invertX <pyqtgraph.ViewBox.invertX> - :func:register <pyqtgraph.ViewBox.register> - :func:unregister <pyqtgraph.ViewBox.unregister>

The ViewBox itself can be accessed by calling :func:getViewBox() <pyqtgraph.PlotItem.getViewBox>

==================== ======================================================================= Signals: sigYRangeChanged wrapped from :class:ViewBox <pyqtgraph.ViewBox> sigXRangeChanged wrapped from :class:ViewBox <pyqtgraph.ViewBox> sigRangeChanged wrapped from :class:ViewBox <pyqtgraph.ViewBox> ==================== =======================================================================

Create a new PlotItem. All arguments are optional. Any extra keyword arguments are passed to :func:PlotItem.plot() <pyqtgraph.PlotItem.plot>.

============== ========================================================================================== Arguments: title Title to display at the top of the item. Html is allowed. labels A dictionary specifying the axis labels to display::

                {'left': (args), 'bottom': (args), ...}

            The name of each axis and the corresponding arguments are passed to 
            :func:`PlotItem.setLabel() <pyqtgraph.PlotItem.setLabel>`
            Optionally, PlotItem my also be initialized with the keyword arguments left,
            right, top, or bottom to achieve the same effect.

name Registers a name for this view so that others may link to it viewBox If specified, the PlotItem will be constructed with this as its ViewBox. axisItems Optional dictionary instructing the PlotItem to use pre-constructed items for its axes. The dict keys must be axis names ('left', 'bottom', 'right', 'top') and the values must be instances of AxisItem (or at least compatible with AxisItem). ============== ==========================================================================================

Expand source code
class TimePlot(RangePlot):

    def __init__(self, aspec, channel, browser, xwidth, ylabel=''):
        # axis:
        bottom_axis = TimeAxisItem(orientation='bottom', showValues=True)
        bottom_axis.setLabel('Time', 's')
        bottom_axis.set_start_time(browser.data.start_time)
        top_axis = TimeAxisItem(orientation='top', showValues=False)
        top_axis.set_start_time(browser.data.start_time)
        left_axis = YAxisItem(orientation='left', showValues=True)
        left_axis.setWidth(8*xwidth)
        if ylabel:
            left_axis.setLabel(ylabel)
        else:
            if browser.data.channels > 4:
                left_axis.setLabel(f'C{channel}')
            else:
                left_axis.setLabel(f'channel {channel}')
        right_axis = YAxisItem(orientation='right', showValues=False)

        # plot:
        RangePlot.__init__(self, aspec, channel, browser,
                           axisItems={'bottom': bottom_axis,
                                      'top': top_axis,
                                      'left': left_axis,
                                      'right': right_axis})

        # design:
        self.getViewBox().setBackgroundColor('black')

        # audio marker:
        self.vmarker = pg.InfiniteLine(angle=90, movable=False)
        self.vmarker.setPen(pg.mkPen('white', width=2))
        self.vmarker.setZValue(100)
        self.vmarker.setValue(-1)
        self.addItem(self.vmarker, ignoreBounds=True)


    def polish(self):
        text_color = self.palette().color(QPalette.Text)
        for axis in ['left', 'right', 'top', 'bottom']:
            self.getAxis(axis).setPen(style=Qt.NoPen)
            self.getAxis(axis).setTickPen(style=Qt.SolidLine)
            self.getAxis(axis).setTextPen(text_color)
        self.getAxis('left').setLabel(self.getAxis('left').labelText,
                                      self.getAxis('left').labelUnits,
                                      color=text_color)
        self.getAxis('bottom').setLabel(self.getAxis('bottom').labelText,
                                        self.getAxis('bottom').labelUnits,
                                        color=text_color)
        
        
    def range(self, axspec):
        if axspec == self.x():
            if len(self.data_items) > 0:
                tmax = self.data_items[0].data.frames/self.data_items[0].data.rate
                return 0, tmax, min(10, tmax)
            else:
                return 0, None, 10
        elif axspec == self.y():
            amin = None
            amax = None
            astep = 1
            for item in self.data_items:
                a0 = item.data.ampl_min
                a1 = item.data.ampl_max
                if amin is None or a0 < amin:
                    amin = a0
                if amax is None or a1 > amax:
                    amax = a1
            if amin is None:
                amin = -1
            if amax is None:
                amax = +1
            return amin, amax, astep


    def amplitudes(self, t0, t1):
        amin = None
        amax = None
        for item in self.data_items:
            i0 = int(np.round(t0*item.rate))
            i1 = int(np.round(t1*item.rate))
            a0 = np.min(item.data[i0:i1, item.channel])
            a1 = np.max(item.data[i0:i1, item.channel])
            if amin is None or a0 < amin:
                amin = a0
            if amax is None or a1 > amax:
                amax = a1
        return amin, amax

    
    def get_marker_pos(self, x0, x1, y):
        for item in reversed(self.data_items):
            if item.isVisible():
                i0 = int(np.round(x0*item.rate))
                i1 = int(np.round(x1*item.rate))
                y0 = np.min(item.data[i0:i1, item.channel])
                y1 = np.max(item.data[i0:i1, item.channel])
                yc = (y0 + y1)/2
                if y >= yc:
                    return x0, y1, None
                else:
                    return x0, y0, None
        return x0, y, None


    def enable_starttime(self, enable):
        """ Enable addition of start time to tick labels.

        Parameters
        ----------
        enable: bool
            If True enable addition of start time to tick labels.
        """
        self.getAxis('bottom').enable_start_time(enable)
        self.getAxis('top').enable_start_time(enable)

Ancestors

  • RangePlot
  • pyqtgraph.graphicsItems.PlotItem.PlotItem.PlotItem
  • pyqtgraph.graphicsItems.GraphicsWidget.GraphicsWidget
  • pyqtgraph.graphicsItems.GraphicsItem.GraphicsItem
  • PyQt5.QtWidgets.QGraphicsWidget
  • PyQt5.QtWidgets.QGraphicsObject
  • PyQt5.QtCore.QObject
  • PyQt5.QtWidgets.QGraphicsItem
  • PyQt5.QtWidgets.QGraphicsLayoutItem
  • sip.wrapper
  • sip.simplewrapper

Subclasses

Methods

def polish(self)
def range(self, axspec)
def amplitudes(self, t0, t1)
def get_marker_pos(self, x0, x1, y)
def enable_starttime(self, enable)

Enable addition of start time to tick labels.

Parameters

enable : bool
If True enable addition of start time to tick labels.

Inherited members