Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pyqtgraph plotwidget多个Y轴绘图位于错误区域_Python_Plot_Axis_Pyqtgraph - Fatal编程技术网

Python pyqtgraph plotwidget多个Y轴绘图位于错误区域

Python pyqtgraph plotwidget多个Y轴绘图位于错误区域,python,plot,axis,pyqtgraph,Python,Plot,Axis,Pyqtgraph,我在通过PlotWidget连接的QT5 gui中有一个嵌入式小部件。 我试图绘制两个实时数据流:电压(self.p1)和电流(self.p2)。左轴上的电压和右轴上的电流。到目前为止,我已将每个数据流与其相关轴关联。 但是,我的问题是当前绘图(self.p2)不在正确的显示区域。此特定的绘图显示在小部件的左上角,它显示在左舵驾驶轴之前。最好通过查看图像来查看问题 看我 我知道问题在于设置功能&self.p2(当前)被放置在错误的位置,但我的搜索没有给出答案。 有人能帮忙吗 用于生成图形的代码

我在通过PlotWidget连接的QT5 gui中有一个嵌入式小部件。 我试图绘制两个实时数据流:电压(self.p1)和电流(self.p2)。左轴上的电压和右轴上的电流。到目前为止,我已将每个数据流与其相关轴关联。 但是,我的问题是当前绘图(self.p2)不在正确的显示区域。此特定的绘图显示在小部件的左上角,它显示在左舵驾驶轴之前。最好通过查看图像来查看问题

看我

我知道问题在于设置功能&self.p2(当前)被放置在错误的位置,但我的搜索没有给出答案。 有人能帮忙吗

用于生成图形的代码在启动时调用一次:

def pg_plot_setup(self): # not working still on left axis
    self.p1 = self.graphicsView.plotItem    

# x axis    
    self.p1.setLabel('bottom', 'Time', units='s', color='g', **{'font-size':'12pt'})
    self.p1.getAxis('bottom').setPen(pg.mkPen(color='g', width=3))

# Y1 axis   
    self.p1.setLabel('left', 'Voltage', units='V', color='r', **{'font-size':'12pt'})
    self.p1.getAxis('left').setPen(pg.mkPen(color='r', width=3))

    self.p2 = pg.ViewBox()  
    self.p1.showAxis('right')
    self.p1.scene().addItem(self.p2)
    self.p1.getAxis('right').linkToView(self.p2)
    self.p2.setXLink(self.p1)

# Y2 axis
    self.p1.setLabel('right', 'Current', units="A", color='c', **{'font-size':'12pt'})  #<font>&Omega;</font>
    self.p1.getAxis('right').setPen(pg.mkPen(color='c', width=3))

我在这里找到了答案

将此
self.p2.setGeometry(self.p1.vb.sceneboundingdirect())
添加到函数“更新图形”中,可在每次更新场景时调整viewbox的大小,但它必须处于更新循环中

或者将此
self.p1.vb.sigResized.connect(self.updateViews)
添加到函数“pg\u plot\u setup”中,作为设置的一部分,然后该函数将自动调用此函数

def updateViews(self):
        self.p2.setGeometry(self.p1.vb.sceneBoundingRect())
每次self.p1更新时调整viewbox(self.p2)的大小。

def updateViews(self):
        self.p2.setGeometry(self.p1.vb.sceneBoundingRect())