Created
September 29, 2020 20:48
-
-
Save symroc/f9c538c5021dbfac4595fcbd7ce8a407 to your computer and use it in GitHub Desktop.
pyqtgraph triaxial plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimeAxisItem(pg.AxisItem): | |
def tickStrings(self, values, scale, spacing): | |
return [datetime.fromtimestamp(value) for value in values] | |
class PlotterDate(): | |
def __init__(self, data, starttime,size=(1280,720)): | |
# Data stuff | |
pg.setConfigOptions(antialias=True) | |
self.t = starttime | |
self.data=data | |
# PyQtGraph stuff | |
self.app = QtGui.QApplication([]) | |
self.view=pg.GraphicsView() | |
self.l=pg.GraphicsLayout() | |
self.l.layout.setSpacing(0.) | |
self.l.setContentsMargins(0., 0., 0., 0.) | |
self.view.setCentralItem(self.l) | |
self.view.show() | |
self.view.resize(*size) | |
self.vbs=[] | |
self.line1=[] | |
self.line2=[] | |
self.date_axis = [TimeAxisItem(orientation='bottom'),\ | |
TimeAxisItem(orientation='bottom'),\ | |
TimeAxisItem(orientation='bottom')] | |
self.plots=[] | |
self.difference=[0,0,0] | |
self.plotTexts=[] | |
for i,v in enumerate (data): | |
c=self.l.addPlot(i,0,axisItems = {'bottom': self.date_axis[i]}) | |
mytext='Difference in Plot {} is 0'.format(i+1) | |
t=pg.TextItem(text=mytext,anchor=(-1,-10*i)) | |
l1=pg.InfiniteLine(0,angle=0,movable=True) | |
l2=pg.InfiniteLine(0,angle=0,movable=True) | |
self.view.addItem(t) | |
c.addItem(l1) | |
c.addItem(l2) | |
l1.sigPositionChangeFinished.connect(self.getpos) | |
l2.sigPositionChangeFinished.connect(self.getpos) | |
c.showGrid(x = True, y = True, alpha = 0.5) | |
c.setLabel('left', 'CH{}'.format(i+1), '') | |
c.disableAutoRange() | |
stuff=c.plot([0],[0],pen=(i,3)) | |
self.line1.append(l1) | |
self.line2.append(l2) | |
self.plotTexts.append(t) | |
if i>0: | |
c.setXLink(self.vbs[0]) | |
self.plots.append(stuff) | |
self.vbs.append(c) | |
self.updateplot() | |
for i in self.vbs: | |
i.enableAutoRange() | |
i.sigXRangeChanged.connect(self.setviewbox) | |
return | |
def getpos(self,li): | |
for i,v in enumerate(self.difference): | |
self.difference[i]=abs(self.line1[i].value()-self.line2[i].value()) | |
text="Difference in Plot {} is {}".format(i+1,self.difference[i]) | |
self.plotTexts[i].setText(text) | |
# print(*self.difference) | |
def updateplot(self): | |
for i,p in enumerate(self.plots): | |
p.setData(self.t, self.data[i]) | |
return | |
def setviewbox(self,vb): | |
vb.disableAutoRange() | |
vb.enableAutoRange(axis='y') | |
vb.setAutoVisible(y=True) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment