最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to enableswap secondary viewbox of plotWidget to listen mouse events in plot area? - Stack Overflow

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论