Как установить положение оси внутри PlotItem

Я создаю приложение для мониторинга данных в реальном времени с использованием PyQt и pyqtgraph. В графическом интерфейсе есть три виджета PlotWidget, расположенных вертикально.

Графики показывают положение датчика. Первый показывает координату X, второй - координату Y, а третий график показывает координату Z. По оси абсцисс отложено время, одинаковое для всех трех графиков.

Моя проблема в том, что горизонтальные положения трех осей ординат (то есть оси Y) смещаются внутри PlotWidget и не выравниваются. Я предполагаю, что это в основном из-за меток на оси Y, для которых может потребоваться больше или меньше места в зависимости от количества отображаемых цифр.

Есть ли здесь способ исправить или вручную установить расположение осей графиков?

Спасибо

Для справки вот как я настроил PlotItems:

ui.graphicsView_x.setLabel("left", text="X", units="m")
ui.graphicsView_y.setLabel("left", text="Y", units="m")
ui.graphicsView_z.setLabel("left", text="Z", units="m")

ui.graphicsView_x.setLabel("bottom", text="Time", units="s")
ui.graphicsView_y.setLabel("bottom", text="Time", units="s")
ui.graphicsView_z.setLabel("bottom", text="Time", units="s")

## Create plot items for speed: we'll only call setData method for data display
colors = ['r','g','b']
## sensor rx1
it_rx1_x = ui.graphicsView_x.plot(clear=False, pen=colors[0])
it_rx1_y = ui.graphicsView_y.plot(clear=False, pen=colors[0])
it_rx1_z = ui.graphicsView_z.plot(clear=False, pen=colors[0])
## sensor rx2
it_rx2_x = ui.graphicsView_x.plot(clear=False, pen=colors[1])
it_rx2_y = ui.graphicsView_y.plot(clear=False, pen=colors[1])
it_rx2_z = ui.graphicsView_z.plot(clear=False, pen=colors[1])
## sensor rx3
it_rx3_x = ui.graphicsView_x.plot(clear=False, pen=colors[2])
it_rx3_y = ui.graphicsView_y.plot(clear=False, pen=colors[2])
it_rx3_z = ui.graphicsView_z.plot(clear=False, pen=colors[2])

## Link axes, so we only have to set one (the x graph in this case)
vBx = ui.graphicsView_x.getPlotItem().getViewBox()
vBy = ui.graphicsView_y.getPlotItem().getViewBox()
vBz = ui.graphicsView_z.getPlotItem().getViewBox()

vBy.linkView(vBy.XAxis, vBx)
vBz.linkView(vBz.XAxis, vBx)

ui.graphicsView_x.show()
ui.graphicsView_y.show()
ui.graphicsView_z.show()

И вот как я рисую:

def updatePlots():

    global xData_Rx1_X
    global xData_Rx1_Y
    global xData_Rx1_Z

    global yData_Rx1_X
    global yData_Rx1_Y
    global yData_Rx1_Z

    global xData_Rx2_X
    global xData_Rx2_Y
    global xData_Rx2_Z

    global yData_Rx2_X
    global yData_Rx2_Y
    global yData_Rx2_Z

    global xData_Rx3_X
    global xData_Rx3_Y
    global xData_Rx3_Z

    global yData_Rx3_X
    global yData_Rx3_Y
    global yData_Rx3_Z

    ## Note: we linked the X axes of the ViewBoxes.  To set the scale of all,
    ## only manipulate the X coordinate plot.

    graphWidth = ui.horizontalSlider.value()


    ## For some reason, Y limits are not properly auto-adjusted when we show
    ## only a portion of the entire data time series (by setting the X-limits
    ## to show only the data of interest).
    ## For this reason, we manually determine and set Y limits 
    maxX = []
    maxY_x = []
    minY_x = []

    maxY_y = []
    minY_y = []

    maxY_z = []
    minY_z = []




    if ui.rx1_checkBox.isChecked() and len(xData_Rx1_X) > 0:
        X , Y = truncateData(xData_Rx1_X,yData_Rx1_X,graphWidth)
        it_rx1_x.setData(np.hstack(X),np.hstack(Y))

        maxX.append(max(X))
        maxY_x.append(max(Y))
        minY_x.append(min(Y))

        X , Y = truncateData(xData_Rx1_Y,yData_Rx1_Y,graphWidth)
        it_rx1_y.setData(np.hstack(X),np.hstack(Y))
        maxY_y.append(max(Y))
        minY_y.append(min(Y))

        X , Y = truncateData(xData_Rx1_Z,yData_Rx1_Z,graphWidth)
        it_rx1_z.setData(np.hstack(X),np.hstack(Y))
        maxY_z.append(max(Y))
        minY_z.append(min(Y))



    if ui.rx2_checkBox.isChecked() and len(xData_Rx2_X) > 0:
        X , Y = truncateData(xData_Rx2_X,yData_Rx2_X,graphWidth)
        it_rx2_x.setData(np.hstack(X),np.hstack(Y))
        maxX.append(max(X))
        maxY_x.append(max(Y))
        minY_x.append(min(Y))

        X , Y = truncateData(xData_Rx2_Y,yData_Rx2_Y,graphWidth)
        it_rx2_y.setData(np.hstack(X),np.hstack(Y))
        maxY_y.append(max(Y))
        minY_y.append(min(Y))

        X , Y = truncateData(xData_Rx2_Z,yData_Rx2_Z,graphWidth)
        it_rx2_z.setData(np.hstack(X),np.hstack(Y))
        maxY_z.append(max(Y))
        minY_z.append(min(Y))

    if ui.rx3_checkBox.isChecked() and len(xData_Rx3_X) > 0:

        X , Y = truncateData(xData_Rx3_X,yData_Rx3_X,graphWidth)
        it_rx3_x.setData(np.hstack(X),np.hstack(Y))
        maxX.append(max(X))
        maxY_x.append(max(Y))
        minY_x.append(min(Y))

        X , Y = truncateData(xData_Rx3_Y,yData_Rx3_Y,graphWidth)
        it_rx3_y.setData(np.hstack(X),np.hstack(Y))
        maxY_y.append(max(Y))
        minY_y.append(min(Y))

        X , Y = truncateData(xData_Rx3_Z,yData_Rx3_Z,graphWidth)
        it_rx3_z.setData(np.hstack(xData_Rx3_Z),np.hstack(yData_Rx3_Z))
        it_rx3_z.setData(np.hstack(X),np.hstack(Y))
        maxY_z.append(max(Y))
        minY_z.append(min(Y))


    ## temporarily delete curves when box is unchecked
    if not ui.rx1_checkBox.isChecked() and len(xData_Rx1_X) > 0:
        it_rx1_x.setData([],[])
        it_rx1_y.setData([],[])
        it_rx1_z.setData([],[])

    if not ui.rx2_checkBox.isChecked() and len(xData_Rx2_X) > 0:
        it_rx2_x.setData([],[])
        it_rx2_y.setData([],[])
        it_rx2_z.setData([],[])

    if not ui.rx3_checkBox.isChecked() and len(xData_Rx3_X) > 0:
        it_rx3_x.setData([],[])
        it_rx3_y.setData([],[])
        it_rx3_z.setData([],[])

    if len(maxX) > 0:
        ## the view boxes are linked, just need to set x plot limits
        ui.graphicsView_x.setXRange(max(maxX) - graphWidth, max(maxX)) 

    if len(minY_x) > 0:
        ui.graphicsView_x.setYRange(min(minY_x), max(maxY_x))
    if len(minY_y) > 0:
        ui.graphicsView_y.setYRange(min(minY_y), max(maxY_y))
    if len(minY_z) > 0:
        ui.graphicsView_z.setYRange(min(minY_z), max(maxY_z))


    ## We don't show the X-label
    ui.graphicsView_x.getPlotItem().showAxis('bottom', show=False)
    ui.graphicsView_x.getPlotItem().showGrid(x=False, y=True, alpha=1.)

    ui.graphicsView_y.getPlotItem().showAxis('bottom', show=False)
    ui.graphicsView_y.getPlotItem().showGrid(x=False, y=True, alpha=1.)

    ui.graphicsView_z.getPlotItem().showAxis('bottom', show=False)
    ui.graphicsView_z.getPlotItem().showGrid(x=False, y=True, alpha=1.)

Вот урезанная версия кода:

import time
import datetime
import numpy as np


import dbus

from dbus.mainloop.qt import DBusQtMainLoop
from PyQt4 import QtCore, QtDBus, QtGui
import pyqtgraph as pg

from upy018_gui import *
import sys



def appendData(X,Y,x,y,maxX):


    if len(X) == 0:
        Xlist = [x]
        Ylist = [y]
    else:

        X.append(x)
        Y.append(y)
        Xarray = np.array(X)

        Yarray = np.array(Y)




        ind, = (Xarray >= Xarray.max() - float(maxX)).nonzero()

        Xarray = Xarray[ind]
        Yarray = Yarray[ind]


        Xlist = Xarray.tolist()
        Ylist = Yarray.tolist()

    return Xlist, Ylist

def truncateData(X,Y,maxX):

    if len(X) > 0:
        Xarray = np.array(X)
        Yarray = np.array(Y)

        ind, = (Xarray >= Xarray.max() - float(maxX)).nonzero()

        Xarray = Xarray[ind]
        Yarray = Yarray[ind]

        Xlist = Xarray.tolist()
        Ylist = Yarray.tolist()

    else:
        Xlist = X
        Ylist = Y
    return Xlist, Ylist


def updatePnO(*arg):

    global maxLengthStored

    global pauseDisplay

    global xData_Rx1_X
    global xData_Rx1_Y
    global xData_Rx1_Z

    global yData_Rx1_X
    global yData_Rx1_Y
    global yData_Rx1_Z

    global xData_Rx2_X
    global xData_Rx2_Y
    global xData_Rx2_Z

    global yData_Rx2_X
    global yData_Rx2_Y
    global yData_Rx2_Z

    global xData_Rx3_X
    global xData_Rx3_Y
    global xData_Rx3_Z

    global yData_Rx3_X
    global yData_Rx3_Y
    global yData_Rx3_Z


    global numUpdatesReceived
    global numReceiversAttached

    receiverID = int(arg[0])

    numUpdatesReceived += 1

    x_update = float(arg[2]) / 1000
    y_update = float(arg[3]) / 1000
    z_update = float(arg[4]) / 1000


    if receiverID == 1:

        xData_Rx1_X,yData_Rx1_X = appendData(xData_Rx1_X,yData_Rx1_X,time.time(),x_update,maxLengthStored)
        xData_Rx1_Y,yData_Rx1_Y = appendData(xData_Rx1_Y,yData_Rx1_Y,time.time(),y_update,maxLengthStored)
        xData_Rx1_Z,yData_Rx1_Z = appendData(xData_Rx1_Z,yData_Rx1_Z,time.time(),z_update,maxLengthStored)


    if receiverID == 2:

        xData_Rx2_X,yData_Rx2_X = appendData(xData_Rx2_X,yData_Rx2_X,time.time(),x_update,maxLengthStored)
        xData_Rx2_Y,yData_Rx2_Y = appendData(xData_Rx2_Y,yData_Rx2_Y,time.time(),y_update,maxLengthStored)
        xData_Rx2_Z,yData_Rx2_Z = appendData(xData_Rx2_Z,yData_Rx2_Z,time.time(),z_update,maxLengthStored)

    if receiverID == 3:

        xData_Rx3_X,yData_Rx3_X = appendData(xData_Rx3_X,yData_Rx3_X,time.time(),x_update,maxLengthStored)
        xData_Rx3_Y,yData_Rx3_Y = appendData(xData_Rx3_Y,yData_Rx3_Y,time.time(),y_update,maxLengthStored)
        xData_Rx3_Z,yData_Rx3_Z = appendData(xData_Rx3_Z,yData_Rx3_Z,time.time(),z_update,maxLengthStored)


    ## only update graphs when we have received an update to all connected receivers
    if not pauseDisplay and numUpdatesReceived == numReceiversAttached:
        updatePlots()

    if numUpdatesReceived >= numReceiversAttached: # can be larger, if we disconnect a receiver at the wrong moment
        numUpdatesReceived = 0


def updatePlots():

    global xData_Rx1_X
    global xData_Rx1_Y
    global xData_Rx1_Z

    global yData_Rx1_X
    global yData_Rx1_Y
    global yData_Rx1_Z

    global xData_Rx2_X
    global xData_Rx2_Y
    global xData_Rx2_Z

    global yData_Rx2_X
    global yData_Rx2_Y
    global yData_Rx2_Z

    global xData_Rx3_X
    global xData_Rx3_Y
    global xData_Rx3_Z

    global yData_Rx3_X
    global yData_Rx3_Y
    global yData_Rx3_Z

    ## Note: we linked the X axes of the ViewBoxes.  To set the scale of all, only manipulate the X coordinate plot.

    graphWidth = ui.horizontalSlider.value()


    ## For some reason, Y limits are not properly auto-adjusted when
    ## we show only a portion of the entire data time series (by setting the X-limits to show only the data of interest).
    ## For this reason, we manually determine and set Y limits 
    maxX = []
    maxY_x = []
    minY_x = []

    maxY_y = []
    minY_y = []

    maxY_z = []
    minY_z = []




    if ui.rx1_checkBox.isChecked() and len(xData_Rx1_X) > 0:
        X , Y = truncateData(xData_Rx1_X,yData_Rx1_X,graphWidth)
        it_rx1_x.setData(np.hstack(X),np.hstack(Y))

        maxX.append(max(X))
        maxY_x.append(max(Y))
        minY_x.append(min(Y))

        X , Y = truncateData(xData_Rx1_Y,yData_Rx1_Y,graphWidth)
        it_rx1_y.setData(np.hstack(X),np.hstack(Y))
        maxY_y.append(max(Y))
        minY_y.append(min(Y))

        X , Y = truncateData(xData_Rx1_Z,yData_Rx1_Z,graphWidth)
        it_rx1_z.setData(np.hstack(X),np.hstack(Y))
        maxY_z.append(max(Y))
        minY_z.append(min(Y))



    if ui.rx2_checkBox.isChecked() and len(xData_Rx2_X) > 0:
        X , Y = truncateData(xData_Rx2_X,yData_Rx2_X,graphWidth)
        it_rx2_x.setData(np.hstack(X),np.hstack(Y))
        maxX.append(max(X))
        maxY_x.append(max(Y))
        minY_x.append(min(Y))

        X , Y = truncateData(xData_Rx2_Y,yData_Rx2_Y,graphWidth)
        it_rx2_y.setData(np.hstack(X),np.hstack(Y))
        maxY_y.append(max(Y))
        minY_y.append(min(Y))

        X , Y = truncateData(xData_Rx2_Z,yData_Rx2_Z,graphWidth)
        it_rx2_z.setData(np.hstack(X),np.hstack(Y))
        maxY_z.append(max(Y))
        minY_z.append(min(Y))

    if ui.rx3_checkBox.isChecked() and len(xData_Rx3_X) > 0:

        X , Y = truncateData(xData_Rx3_X,yData_Rx3_X,graphWidth)
        it_rx3_x.setData(np.hstack(X),np.hstack(Y))
        maxX.append(max(X))
        maxY_x.append(max(Y))
        minY_x.append(min(Y))

        X , Y = truncateData(xData_Rx3_Y,yData_Rx3_Y,graphWidth)
        it_rx3_y.setData(np.hstack(X),np.hstack(Y))
        maxY_y.append(max(Y))
        minY_y.append(min(Y))

        X , Y = truncateData(xData_Rx3_Z,yData_Rx3_Z,graphWidth)
        it_rx3_z.setData(np.hstack(xData_Rx3_Z),np.hstack(yData_Rx3_Z))
        it_rx3_z.setData(np.hstack(X),np.hstack(Y))
        maxY_z.append(max(Y))
        minY_z.append(min(Y))


    ## temporarily delete curves when box is unchecked
    if not ui.rx1_checkBox.isChecked() and len(xData_Rx1_X) > 0:
        it_rx1_x.setData([],[])
        it_rx1_y.setData([],[])
        it_rx1_z.setData([],[])

    if not ui.rx2_checkBox.isChecked() and len(xData_Rx2_X) > 0:
        it_rx2_x.setData([],[])
        it_rx2_y.setData([],[])
        it_rx2_z.setData([],[])

    if not ui.rx3_checkBox.isChecked() and len(xData_Rx3_X) > 0:
        it_rx3_x.setData([],[])
        it_rx3_y.setData([],[])
        it_rx3_z.setData([],[])


    if len(maxX) > 0:
        ## the view boxes are linked, just need to set x plot limits
        ui.graphicsView_x.setXRange(max(maxX) - graphWidth, max(maxX)) 

    if len(minY_x) > 0:
        ui.graphicsView_x.setYRange(min(minY_x), max(maxY_x))
    if len(minY_y) > 0:
        ui.graphicsView_y.setYRange(min(minY_y), max(maxY_y))
    if len(minY_z) > 0:
        ui.graphicsView_z.setYRange(min(minY_z), max(maxY_z))


def sliderAdjusted():
    global graphWidth
    graphWidth = float(ui.horizontalSlider.value())
    thestring = "Window width: %d s" % graphWidth
    ui.graphWidth_label.setText(thestring)

def clickedOnGraph_x(self):
    pass
def clickedOnGraph_y(self):
    pass
def clickedOnGraph_z(self):
    pass



def pause():
    global pauseDisplay

    global launchTime

    global xData_Rx1_X
    global xData_Rx1_Y
    global xData_Rx1_Z

    global yData_Rx1_X
    global yData_Rx1_Y
    global yData_Rx1_Z

    global xData_Rx2_X
    global xData_Rx2_Y
    global xData_Rx2_Z

    global yData_Rx2_X
    global yData_Rx2_Y
    global yData_Rx2_Z

    global xData_Rx3_X
    global xData_Rx3_Y
    global xData_Rx3_Z

    global yData_Rx3_X
    global yData_Rx3_Y
    global yData_Rx3_Z





    pauseDisplay = True
    ui.pause_toolButton.hide()
    ui.graphWidth_label.hide()
    ui.start_toolButton.show()
    ui.horizontalSlider.hide()


    ui.graphicsView_x.getViewBox().enableAutoRange()
    ui.graphicsView_y.getViewBox().enableAutoRange()
    ui.graphicsView_z.getViewBox().enableAutoRange()

    if ui.rx1_checkBox.isChecked() and len(xData_Rx1_X) > 0:
        it_rx1_x.setData(np.hstack(xData_Rx1_X)-launchTime,np.hstack(yData_Rx1_X))
        it_rx1_y.setData(np.hstack(xData_Rx1_Y)-launchTime,np.hstack(yData_Rx1_Y))
        it_rx1_z.setData(np.hstack(xData_Rx1_Z)-launchTime,np.hstack(yData_Rx1_Z))


    if ui.rx2_checkBox.isChecked() and len(xData_Rx2_X) > 0:
        it_rx2_x.setData(np.hstack(xData_Rx2_X)-launchTime,np.hstack(yData_Rx2_X))
        it_rx2_y.setData(np.hstack(xData_Rx2_Y)-launchTime,np.hstack(yData_Rx2_Y))
        it_rx2_z.setData(np.hstack(xData_Rx2_Z)-launchTime,np.hstack(yData_Rx2_Z))


    if ui.rx3_checkBox.isChecked() and len(xData_Rx3_X) > 0:
        it_rx3_x.setData(np.hstack(xData_Rx3_X)-launchTime,np.hstack(yData_Rx3_X))
        it_rx3_y.setData(np.hstack(xData_Rx3_Y)-launchTime,np.hstack(yData_Rx3_Y))
        it_rx3_z.setData(np.hstack(xData_Rx3_Z)-launchTime,np.hstack(yData_Rx3_Z))

    ## temporarily delete curves when box is unchecked
    if not ui.rx1_checkBox.isChecked() and len(xData_Rx1_X) > 0:
        it_rx1_x.setData([],[])
        it_rx1_y.setData([],[])
        it_rx1_z.setData([],[])

    if not ui.rx2_checkBox.isChecked() and len(xData_Rx2_X) > 0:
        it_rx2_x.setData([],[])
        it_rx2_y.setData([],[])
        it_rx2_z.setData([],[])

    if not ui.rx3_checkBox.isChecked() and len(xData_Rx3_X) > 0:
        it_rx3_x.setData([],[])
        it_rx3_y.setData([],[])
        it_rx3_z.setData([],[])

    ui.graphicsView_x.getPlotItem().showAxis('bottom', show=True)
    ui.graphicsView_y.getPlotItem().showAxis('bottom', show=True)
    ui.graphicsView_z.getPlotItem().showAxis('bottom', show=True)

    #print(ui.graphicsView_x.getPlotItem().viewRange())

def restart():
    global pauseDisplay
    pauseDisplay = False
    ui.pause_toolButton.show()
    ui.graphWidth_label.show()
    ui.start_toolButton.hide()
    ui.horizontalSlider.show()

    ui.graphicsView_x.getPlotItem().showAxis('bottom', show=False)
    ui.graphicsView_y.getPlotItem().showAxis('bottom', show=False)
    ui.graphicsView_z.getPlotItem().showAxis('bottom', show=False)


def getOut():
    app.quit()

# ======================================= #
#                                         #
#                MAIN                     #
#                                         #
# ======================================= #


if __name__ == '__main__':


    ## Global variables
    graphWidthMax = 45. # maximum data length that can be shown while data acquisition is running (seconds)
    graphWidth = 30. # data length shown in graph at program launch (seconds)
    maxLengthStored = 120.# stores up to this many seconds worth of data
    pauseDisplay = False

    numUpdatesReceived = 0
    numReceiversAttached = 0

    xData_Rx1_X = []
    xData_Rx1_Y = []
    xData_Rx1_Z = []

    yData_Rx1_X = []
    yData_Rx1_Y = []
    yData_Rx1_Z = []

    xData_Rx2_X = []
    xData_Rx2_Y = []
    xData_Rx2_Z = []

    yData_Rx2_X = []
    yData_Rx2_Y = []
    yData_Rx2_Z = []

    xData_Rx3_X = []
    xData_Rx3_Y = []
    xData_Rx3_Z = []

    yData_Rx3_X = []
    yData_Rx3_Y = []
    yData_Rx3_Z = []

    ## Create application
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)


    DBusQtMainLoop(set_as_default=True)     


    ## set up DBus communication    
    bus = dbus.SessionBus()     

    signalReceiver_positionAndOrientationUpdate = bus.add_signal_receiver(updatePnO,"positionUpdate","tcf.PositionService","tcf.PositionService","/")

    ## Construct an interface object for method calls
    #     First, obtain proxy object
    remote_object = bus.get_object("tcf.PositionService", "/")
    trackerService = dbus.Interface(remote_object, 'tcf.PositionService')

    ui.quit_pushButton.connect(ui.quit_pushButton,QtCore.SIGNAL("clicked()"),getOut)



    ui.horizontalSlider.setMaximum(graphWidthMax)
    ui.horizontalSlider.setMinimum(5)
    ui.horizontalSlider.setValue(graphWidth)
    ui.horizontalSlider.connect(ui.horizontalSlider,QtCore.SIGNAL("valueChanged(int)"),sliderAdjusted)

    enableChangeCheckBoxes("initialize")


    thestring = "Window width: %d s" % graphWidth
    ui.graphWidth_label.setText(thestring)


    icon = QtGui.QIcon('./upy018_ICON_pause.png')
    ui.pause_toolButton.setIcon(icon)
    ui.pause_toolButton.connect(ui.pause_toolButton,QtCore.SIGNAL("clicked()"),pause)


    icon = QtGui.QIcon('./upy018_ICON_play.png')
    ui.start_toolButton.setIcon(icon)
    ui.start_toolButton.hide()
    ui.start_toolButton.connect(ui.start_toolButton,QtCore.SIGNAL("clicked()"),restart)


    ## Set up P&O graphs




    ui.graphicsView_x.setLabel("left", text="X", units="m")
    ui.graphicsView_y.setLabel("left", text="Y", units="m")
    ui.graphicsView_z.setLabel("left", text="Z", units="m")

    ui.graphicsView_x.setLabel("bottom", text="Time", units="s")
    ui.graphicsView_y.setLabel("bottom", text="Time", units="s")
    ui.graphicsView_z.setLabel("bottom", text="Time", units="s")

    #ui.graphicsView_x.getPlotItem().getAxis('left').setWidth(100)
    #ui.graphicsView_y.getPlotItem().getAxis('left').setWidth(100)
    #ui.graphicsView_z.getPlotItem().getAxis('left').setWidth(100)

    ## Create plot items for speed: we'll only call setData method for data display
    colors = ['r','g','b']
    it_rx1_x = ui.graphicsView_x.plot(clear=False, pen=colors[0])
    it_rx1_y = ui.graphicsView_y.plot(clear=False, pen=colors[0])
    it_rx1_z = ui.graphicsView_z.plot(clear=False, pen=colors[0])

    it_rx2_x = ui.graphicsView_x.plot(clear=False, pen=colors[1])
    it_rx2_y = ui.graphicsView_y.plot(clear=False, pen=colors[1])
    it_rx2_z = ui.graphicsView_z.plot(clear=False, pen=colors[1])

    it_rx3_x = ui.graphicsView_x.plot(clear=False, pen=colors[2])
    it_rx3_y = ui.graphicsView_y.plot(clear=False, pen=colors[2])
    it_rx3_z = ui.graphicsView_z.plot(clear=False, pen=colors[2])

    ## Link axes, so we only have to set one (the x graph in this case)
    vBx = ui.graphicsView_x.getPlotItem().getViewBox()
    vBy = ui.graphicsView_y.getPlotItem().getViewBox()
    vBz = ui.graphicsView_z.getPlotItem().getViewBox()

    vBy.linkView(vBy.XAxis, vBx)
    vBz.linkView(vBz.XAxis, vBx)

    ui.graphicsView_y.setXLink(ui.graphicsView_x)
    ui.graphicsView_z.setXLink(ui.graphicsView_x)



    ## We don't show the X-label, unless we pause
    ui.graphicsView_x.getPlotItem().showAxis('bottom', show=False)
    ui.graphicsView_x.getPlotItem().showGrid(x=False, y=True, alpha=1.)

    ui.graphicsView_y.getPlotItem().showAxis('bottom', show=False)
    ui.graphicsView_y.getPlotItem().showGrid(x=False, y=True, alpha=1.)

    ui.graphicsView_z.getPlotItem().showAxis('bottom', show=False)
    ui.graphicsView_z.getPlotItem().showGrid(x=False, y=True, alpha=1.)

    ui.graphicsView_y.setXLink(ui.graphicsView_x)
    ui.graphicsView_z.setXLink(ui.graphicsView_x)

    ## The commands below will only be working in pyqtgraph version  0.9.9
    #ui.graphicsView_x.getPlotItem().getAxis('left').setStyle(tickTextWidth=60)
    #ui.graphicsView_y.getPlotItem().getAxis('left').setStyle(tickTextWidth=60)
    #ui.graphicsView_z.getPlotItem().getAxis('left').setStyle(tickTextWidth=60)

    #ui.graphicsView_x.getPlotItem().getAxis('left').setWidth(250)
    #vBx.disableAutoRange(vBx.XAxis)
    #vBy.disableAutoRange(vBy.XAxis)
    #vBz.disableAutoRange(vBz.XAxis)


    #ui.graphicsView_x.getPlotItem().getAxis('left').setTicks([[(0, 'zero'), (0.020, 'twenty')]])
    #ui.graphicsView_y.getPlotItem().getAxis('left').setTicks([[(1, 'one'), (2, 'two')]])
    #ui.graphicsView_z.getPlotItem().getAxis('left').setTicks([[(1, 'one'), (2, 'two')]])

    ui.graphicsView_x.show()
    ui.graphicsView_y.show()
    ui.graphicsView_z.show()

    launchTime = time.time()


    MainWindow.show()

    sys.exit(app.exec_())

person Tobias    schedule 05.08.2014    source источник


Ответы (1)


Я рекомендую связать оси x вместе; это гарантирует, что их значения выровнены друг с другом независимо от размера оси y. См. pyqtgraph/examples/linkedViews.py.

Может быть, примерно так:

ui.graphicsView_y.setXLink(ui.graphicsView_x)
ui.graphicsView_z.setXLink(ui.graphicsView_x)
person Luke    schedule 06.08.2014
comment
Хм, это не помогло. Я понял, что часть проблемы заключается в том, что связывание осей помогает только в том случае, если вы связываете ось с самыми большими строками меток. Однако мне удалось вручную установить для ширины оси большое значение для размещения больших строк меток: ui.graphicsView_x.getPlotItem().getAxis('left').setWidth(100) ui.graphicsView_y.getPlotItem().getAxis('left').setWidth(100) ui.graphicsView_z.getPlotItem().getAxis('left').setWidth(100) Однако это значение перезаписывается, и оси прыгают вперед и назад. есть ли настройка, чтобы сделать ширину постоянной? - person Tobias; 08.08.2014
comment
Связывание должно работать независимо от относительных размеров осей ... может быть ошибкой pyqtgraph, но без более полного примера сложно сказать. - person Luke; 08.08.2014
comment
Спасибо. Я добавил более полную версию кода. - person Tobias; 08.08.2014