最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin6PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far