- sync with lp:pyqtgraph (missing changes in PlotItem.py)
This commit is contained in:
parent
3b820c2972
commit
90fb5d04d4
109
PlotItem.py
109
PlotItem.py
@ -20,6 +20,7 @@ This class is very heavily featured:
|
||||
from graphicsItems import *
|
||||
from plotConfigTemplate import *
|
||||
from PyQt4 import QtGui, QtCore, QtSvg
|
||||
from functions import *
|
||||
#from ObjectWorkaround import *
|
||||
#tryWorkaround(QtCore, QtGui)
|
||||
import weakref
|
||||
@ -43,7 +44,7 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
lastFileDir = None
|
||||
managers = {}
|
||||
|
||||
def __init__(self, parent=None, name=None):
|
||||
def __init__(self, parent=None, name=None, labels=None, **kargs):
|
||||
QtGui.QGraphicsWidget.__init__(self, parent)
|
||||
|
||||
## Set up control buttons
|
||||
@ -226,6 +227,15 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
if name is not None:
|
||||
self.registerPlot(name)
|
||||
|
||||
if labels is not None:
|
||||
for k in labels:
|
||||
if isinstance(labels[k], basestring):
|
||||
labels[k] = (labels[k],)
|
||||
self.setLabel(k, *labels[k])
|
||||
|
||||
if len(kargs) > 0:
|
||||
self.plot(**kargs)
|
||||
|
||||
|
||||
def __del__(self):
|
||||
if self.manager is not None:
|
||||
@ -274,8 +284,8 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
v = self.scene().views()[0]
|
||||
b = self.vb.mapRectToScene(self.vb.boundingRect())
|
||||
wr = v.mapFromScene(b).boundingRect()
|
||||
pos = v.pos()
|
||||
wr.adjust(v.x(), v.y(), v.x(), v.y())
|
||||
pos = v.mapToGlobal(v.pos())
|
||||
wr.adjust(pos.x(), pos.y(), pos.x(), pos.y())
|
||||
return wr
|
||||
|
||||
|
||||
@ -324,6 +334,7 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
self.manager.linkY(self, plot)
|
||||
|
||||
def linkXChanged(self, plot):
|
||||
"""Called when a linked plot has changed its X scale"""
|
||||
#print "update from", plot
|
||||
if self.linksBlocked:
|
||||
return
|
||||
@ -337,11 +348,13 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
x1 = pr.left() + (sg.x()-pg.x()) * upp
|
||||
x2 = x1 + sg.width() * upp
|
||||
plot.blockLink(True)
|
||||
self.setManualXScale()
|
||||
self.setXRange(x1, x2, padding=0)
|
||||
plot.blockLink(False)
|
||||
self.replot()
|
||||
|
||||
def linkYChanged(self, plot):
|
||||
"""Called when a linked plot has changed its Y scale"""
|
||||
if self.linksBlocked:
|
||||
return
|
||||
pr = plot.vb.viewRect()
|
||||
@ -351,6 +364,7 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
y1 = pr.bottom() + (sg.y()-pg.y()) * upp
|
||||
y2 = y1 + sg.height() * upp
|
||||
plot.blockLink(True)
|
||||
self.setManualYScale()
|
||||
self.setYRange(y1, y2, padding=0)
|
||||
plot.blockLink(False)
|
||||
self.replot()
|
||||
@ -554,7 +568,7 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
self.curves.remove(item)
|
||||
self.updateDecimation()
|
||||
self.updateParamList()
|
||||
item.connect(QtCore.SIGNAL('plotChanged'), self.plotChanged)
|
||||
item.connect(item, QtCore.SIGNAL('plotChanged'), self.plotChanged)
|
||||
|
||||
def clear(self):
|
||||
for i in self.items[:]:
|
||||
@ -567,7 +581,18 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
self.avgCurves = {}
|
||||
|
||||
|
||||
def plot(self, data=None, x=None, clear=False, params=None, pen=None):
|
||||
def plot(self, data=None, data2=None, x=None, y=None, clear=False, params=None, pen=None):
|
||||
"""Add a new plot curve. Data may be specified a few ways:
|
||||
plot(yVals) # x vals will be integers
|
||||
plot(xVals, yVals)
|
||||
plot(y=yVals, x=xVals)
|
||||
"""
|
||||
if y is not None:
|
||||
data = y
|
||||
if data2 is not None:
|
||||
x = data
|
||||
data = data2
|
||||
|
||||
if clear:
|
||||
self.clear()
|
||||
if params is None:
|
||||
@ -588,7 +613,7 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
#print data, curve
|
||||
self.addCurve(curve, params)
|
||||
if pen is not None:
|
||||
curve.setPen(pen)
|
||||
curve.setPen(mkPen(pen))
|
||||
|
||||
return curve
|
||||
|
||||
@ -619,7 +644,7 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
if self.ctrl.averageGroup.isChecked():
|
||||
self.addAvgCurve(c)
|
||||
|
||||
c.connect(QtCore.SIGNAL('plotChanged'), self.plotChanged)
|
||||
c.connect(c, QtCore.SIGNAL('plotChanged'), self.plotChanged)
|
||||
self.plotChanged()
|
||||
|
||||
def plotChanged(self, curve=None):
|
||||
@ -643,6 +668,7 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
mn -= 1
|
||||
mx += 1
|
||||
self.setRange(ax, mn, mx)
|
||||
#print "Auto range:", ax, mn, mx
|
||||
|
||||
def replot(self):
|
||||
self.plotChanged()
|
||||
@ -880,23 +906,6 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
# disables panning the whole scene by mousewheel
|
||||
ev.accept()
|
||||
|
||||
#def mousePressEvent(self, ev):
|
||||
#self.mousePos = array([ev.pos().x(), ev.pos().y()])
|
||||
#self.pressPos = self.mousePos.copy()
|
||||
#QtGui.QGraphicsWidget.mousePressEvent(self, ev)
|
||||
## NOTE: we will only receive move/release events if we run ev.accept()
|
||||
#print 'press'
|
||||
|
||||
#def mouseReleaseEvent(self, ev):
|
||||
#pos = array([ev.pos().x(), ev.pos().y()])
|
||||
#print 'release'
|
||||
#if sum(abs(self.pressPos - pos)) < 3: ## Detect click
|
||||
#if ev.button() == QtCore.Qt.RightButton:
|
||||
#print 'popup'
|
||||
#self.ctrlMenu.popup(self.mapToGlobal(ev.pos()))
|
||||
#self.mousePos = pos
|
||||
#QtGui.QGraphicsWidget.mouseReleaseEvent(self, ev)
|
||||
|
||||
def resizeEvent(self, ev):
|
||||
self.ctrlBtn.move(0, self.size().height() - self.ctrlBtn.size().height())
|
||||
self.autoBtn.move(self.ctrlBtn.width(), self.size().height() - self.autoBtn.size().height())
|
||||
@ -908,14 +917,8 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
def ctrlBtnClicked(self):
|
||||
self.ctrlMenu.popup(self.mouseScreenPos)
|
||||
|
||||
#def _checkLabelKey(self, key):
|
||||
#if key not in self.labels:
|
||||
#raise Exception("Label '%s' not found. Labels are: %s" % (key, str(self.labels.keys())))
|
||||
|
||||
def getLabel(self, key):
|
||||
pass
|
||||
#self._checkLabelKey(key)
|
||||
#return self.labels[key]['item']
|
||||
|
||||
def _checkScaleKey(self, key):
|
||||
if key not in self.scales:
|
||||
@ -927,43 +930,9 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
|
||||
def setLabel(self, key, text=None, units=None, unitPrefix=None, **args):
|
||||
self.getScale(key).setLabel(text=text, units=units, unitPrefix=unitPrefix, **args)
|
||||
#if text is not None:
|
||||
#self.labels[key]['text'] = text
|
||||
#if units != None:
|
||||
#self.labels[key]['units'] = units
|
||||
#if unitPrefix != None:
|
||||
#self.labels[key]['unitPrefix'] = unitPrefix
|
||||
|
||||
#text = self.labels[key]['text']
|
||||
#units = self.labels[key]['units']
|
||||
#unitPrefix = self.labels[key]['unitPrefix']
|
||||
|
||||
#if text is not '' or units is not '':
|
||||
#l = self.getLabel(key)
|
||||
#l.setText("%s (%s%s)" % (text, unitPrefix, units), **args)
|
||||
#self.showLabel(key)
|
||||
|
||||
|
||||
def showLabel(self, key, show=True):
|
||||
self.getScale(key).showLabel(show)
|
||||
#l = self.getLabel(key)
|
||||
#p = self.labels[key]['pos']
|
||||
#if show:
|
||||
#l.show()
|
||||
#if key in ['left', 'right']:
|
||||
#self.layout.setColumnFixedWidth(p[1], l.size().width())
|
||||
#l.setMaximumWidth(20)
|
||||
#else:
|
||||
#self.layout.setRowFixedHeight(p[0], l.size().height())
|
||||
#l.setMaximumHeight(20)
|
||||
#else:
|
||||
#l.hide()
|
||||
#if key in ['left', 'right']:
|
||||
#self.layout.setColumnFixedWidth(p[1], 0)
|
||||
#l.setMaximumWidth(0)
|
||||
#else:
|
||||
#self.layout.setRowFixedHeight(p[0], 0)
|
||||
#l.setMaximumHeight(0)
|
||||
|
||||
def setTitle(self, title=None, **args):
|
||||
if title is None:
|
||||
@ -981,20 +950,8 @@ class PlotItem(QtGui.QGraphicsWidget):
|
||||
p = self.scales[key]['pos']
|
||||
if show:
|
||||
s.show()
|
||||
#if key in ['left', 'right']:
|
||||
#self.layout.setColumnFixedWidth(p[1], s.maximumWidth())
|
||||
##s.setMaximumWidth(40)
|
||||
#else:
|
||||
#self.layout.setRowFixedHeight(p[0], s.maximumHeight())
|
||||
#s.setMaximumHeight(20)
|
||||
else:
|
||||
s.hide()
|
||||
#if key in ['left', 'right']:
|
||||
#self.layout.setColumnFixedWidth(p[1], 0)
|
||||
##s.setMaximumWidth(0)
|
||||
#else:
|
||||
#self.layout.setRowFixedHeight(p[0], 0)
|
||||
#s.setMaximumHeight(0)
|
||||
|
||||
def _plotArray(self, arr, x=None):
|
||||
if arr.ndim != 1:
|
||||
|
Loading…
x
Reference in New Issue
Block a user