How to make the zeros coincide in a PyQtGraph?

91 Views Asked by At

I have 3 axes (left, bottom, right) and I can't find a way for the zeros to all be on the bottom left (see figure) please advise?

enter image description here

Here's part of my code:

    grid = QtWidgets.QGridLayout(self.Envtab)
    grid.setSpacing(10)
    
    plotWidget = PlotWidget(self.tab)
    grid.addWidget(plotWidget, 0, 1, 6, 10)
    
    leftAxisTemperature = plotWidget.plotItem
    leftAxisTemperature.setLabels(bottom='Time [s]', left='Temperature [K]', right='Power [%]', top=' ')
    
    rightViewBox = ViewBox()
    leftAxisTemperature.showAxis('right')
    leftAxisTemperature.scene().addItem(self.rightViewBox)
    leftAxisTemperature.getAxis('right').linkToView(rightViewBox)
    rightViewBox.setXLink(self.leftAxisTemperature)
    
    sampleTemperatureCurve = leftAxisTemperature.plot([], pen='b')
    targetTemperatureCurve = leftAxisTemperature.plot([], pen='r')
    qPidCurve = PlotCurveItem(pen='k')
    qAuxCurve = PlotCurveItem(pen='k')
    rightViewBox.addItem(qPidCurve)
    rightViewBox.addItem(qAuxCurve)
    
    dy = [(v, str(v)) for v in [0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325]]
    plotWidget.getAxis('left').setTicks([dy, []])
    
    leftAxisTemperature.setYRange(0, 300) 
    rightViewBox.setYRange(0, 100)
    
    plotWidget.getAxis('bottom').setPen('k')
    plotWidget.getAxis('bottom').setTextPen('k')
    plotWidget.getAxis('left').setPen('b')
    plotWidget.getAxis('left').setTextPen('b')
    plotWidget.getAxis('right').setPen('k')
    plotWidget.getAxis('right').setTextPen('k')
    plotWidget.getAxis('top').setTextPen(QColor(QtCore.Qt.transparent))
    

Every so often the data is gathered in from an array and plotted as per:

    timeTemperature, sampleTemperature, targetTemperature, timePressure, pressure, qPid, qAux = self.dm.getData()
    
    sampleTemperatureCurve.setData(np.array(timeTemperature), np.array(sampleTemperature))
    targetTemperatureCurve.setData(np.array(timeTemperature), np.array(targetTemperature))
    qPidCurve.setData(np.array(timeTemperature), np.array(qPid))
    qAuxCurve.setData(np.array(timeTemperature), np.array(qAux))
    rightViewBox.setGeometry(leftAxisTemperature.vb.sceneBoundingRect())
    rightViewBox.linkedViewChanged(leftAxisTemperature.vb, rightViewBox.XAxis)
0

There are 0 best solutions below