예제 #1
0
 def plot(self, data):
     #self.layout.clear()
     self.plots = []
         
     if HAVE_METAARRAY and isinstance(data, MetaArray):
         if data.ndim != 2:
             raise Exception("MultiPlot currently only accepts 2D MetaArray.")
         ic = data.infoCopy()
         ax = 0
         for i in [0, 1]:
             if 'cols' in ic[i]:
                 ax = i
                 break
         #print "Plotting using axis %d as columns (%d plots)" % (ax, data.shape[ax])
         for i in range(data.shape[ax]):
             pi = PlotItem()
             sl = [slice(None)] * 2
             sl[ax] = i
             pi.plot(data[tuple(sl)])
             self.layout.addItem(pi, i, 0)
             self.plots.append((pi, i, 0))
             title = None
             units = None
             info = ic[ax]['cols'][i]
             if 'title' in info:
                 title = info['title']
             elif 'name' in info:
                 title = info['name']
             if 'units' in info:
                 units = info['units']
                 
             pi.setLabel('left', text=title, units=units)
             
     else:
         raise Exception("Data type %s not (yet?) supported for MultiPlot." % type(data))
예제 #2
0
class PlotWidget(GraphicsView):
    
    sigRangeChanged = QtCore.Signal(object, object)
    
    """Widget implementing a graphicsView with a single PlotItem inside."""
    def __init__(self, parent=None, **kargs):
        GraphicsView.__init__(self, parent)
        self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        self.enableMouse(False)
        self.plotItem = PlotItem(**kargs)
        self.setCentralItem(self.plotItem)
        ## Explicitly wrap methods from plotItem
        for m in ['addItem', 'removeItem', 'autoRange', 'clear', 'setXRange', 'setYRange']:
            setattr(self, m, getattr(self.plotItem, m))
        #QtCore.QObject.connect(self.plotItem, QtCore.SIGNAL('viewChanged'), self.viewChanged)
        self.plotItem.sigRangeChanged.connect(self.viewRangeChanged)
                
    #def __dtor__(self):
        ##print "Called plotWidget sip destructor"
        #self.quit()
        
        
    #def quit(self):

    def close(self):
        self.plotItem.close()
        self.plotItem = None
        #self.scene().clear()
        #self.mPlotItem.close()
        self.setParent(None)
        GraphicsView.close(self)

    def __getattr__(self, attr):  ## implicitly wrap methods from plotItem
        if hasattr(self.plotItem, attr):
            m = getattr(self.plotItem, attr)
            if hasattr(m, '__call__'):
                return m
        raise exceptions.NameError(attr)
            
    def viewRangeChanged(self, view, range):
        #self.emit(QtCore.SIGNAL('viewChanged'), *args)
        self.sigRangeChanged.emit(self, range)

    def widgetGroupInterface(self):
        return (None, PlotWidget.saveState, PlotWidget.restoreState)

    def saveState(self):
        return self.plotItem.saveState()
        
    def restoreState(self, state):
        return self.plotItem.restoreState(state)
        
    def getPlotItem(self):
        return self.plotItem
        
        
        
예제 #3
0
 def __init__(self, parent=None, **kargs):
     GraphicsView.__init__(self, parent)
     self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
     self.enableMouse(False)
     self.plotItem = PlotItem(**kargs)
     self.setCentralItem(self.plotItem)
     ## Explicitly wrap methods from plotItem
     for m in ['addItem', 'removeItem', 'autoRange', 'clear', 'setXRange', 'setYRange']:
         setattr(self, m, getattr(self.plotItem, m))
     #QtCore.QObject.connect(self.plotItem, QtCore.SIGNAL('viewChanged'), self.viewChanged)
     self.plotItem.sigRangeChanged.connect(self.viewRangeChanged)
예제 #4
0
파일: PlotWidget.py 프로젝트: Xifax/muscale
 def __init__(self, parent=None, **kargs):
     GraphicsView.__init__(self, parent)
     self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
     self.enableMouse(False)
     self.plotItem = PlotItem(**kargs)
     self.setCentralItem(self.plotItem)
     ## Explicitly wrap methods from plotItem
     for m in ['addItem', 'removeItem', 'autoRange', 'clear', 'setXRange', 'setYRange']:
         setattr(self, m, getattr(self.plotItem, m))
     QtCore.QObject.connect(self.plotItem, QtCore.SIGNAL('viewChanged'), self.viewChanged)
예제 #5
0
파일: PlotWidget.py 프로젝트: jerkos/metms
 def __init__(self, minX, maxX, maxY, parent=None, **kargs):#minX, maxX, maxY
     GraphicsView.__init__(self, parent)
     self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
     self.enableMouse(False)
     try:
         del kargs['useOpenGL']
     except KeyError:
         pass
     self.plotItem = PlotItem(minX, maxX, maxY, **kargs)#minX, maxX, maxY,
     self.setCentralItem(self.plotItem)
     ## Explicitly wrap methods from plotItem
     for m in ['addItem', 'removeItem', 'autoRange', 'clear', 'setXRange', 'setYRange']:
         setattr(self, m, getattr(self.plotItem, m))
     #QtCore.QObject.connect(self.plotItem, QtCore.SIGNAL('viewChanged'), self.viewChanged)
     self.plotItem.sigRangeChanged.connect(self.viewRangeChanged)     
예제 #6
0
    def plot(self, data):
        #self.layout.clear()
        self.plots = []

        if HAVE_METAARRAY and isinstance(data, MetaArray):
            if data.ndim != 2:
                raise Exception(
                    "MultiPlot currently only accepts 2D MetaArray.")
            ic = data.infoCopy()
            ax = 0
            for i in [0, 1]:
                if 'cols' in ic[i]:
                    ax = i
                    break
            #print "Plotting using axis %d as columns (%d plots)" % (ax, data.shape[ax])
            for i in range(data.shape[ax]):
                pi = PlotItem()
                sl = [slice(None)] * 2
                sl[ax] = i
                pi.plot(data[tuple(sl)])
                self.layout.addItem(pi, i, 0)
                self.plots.append((pi, i, 0))
                title = None
                units = None
                info = ic[ax]['cols'][i]
                if 'title' in info:
                    title = info['title']
                elif 'name' in info:
                    title = info['name']
                if 'units' in info:
                    units = info['units']

                pi.setLabel('left', text=title, units=units)

        else:
            raise Exception(
                "Data type %s not (yet?) supported for MultiPlot." %
                type(data))