admin管理员组

文章数量:1435859

I have a PlotWidget with several plotDataItems showed. I'm trying to isolate one or several plots, place them up or down in the graph, and use mouse to zoom and scaling over the plot area as I do with the "main group" of plots.

I tried to make a new viewbox and add it to mainGraph plotwidget after pushing a button, and it works. But mouse events seem to be catched in the plotting area ONLY by the main viewbox. I know that I can Y-scale that plot using the wheel over the new axis, but not over the plot area. That's the challenge.

This is the button connected method that I use to create and link the new viewbox to mainGraph:

def rePlotChannelWithAxisRight(self, channel):
    ## create a new ViewBox, link the right axis to its coordinate system
    self.p1 = self.mainGraph.getPlotItem()
    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)
    self.p1.getAxis('right').setLabel('axis2', color='#0000ff')
    self.updateViews()
    self.p1.vb.sigResized.connect(self.updateViews)

    # Remove plot from mainGraph 
    self.mainGraph.removeItem(self.graphPlots[channel.ID])
    # Add plot to secondary viewbox 
    self.p2.addItem(self.graphPlots[channel.ID])

def updateViews(self):
    ## view has resized; update auxiliary views to match
    self.p2.setGeometry(self.p1.vb.sceneBoundingRect())

    self.p2.linkedViewChanged(self.p1.vb, self.p2.XAxis)

Please, any solution for this will be very appreciated.

Thank you in advance.

本文标签: pythonHow to enableswap secondary viewbox of plotWidget to listen mouse events in plot areaStack Overflow