PlotWidget Log Mode and getting the real value when log mode is enabled

34 views
Skip to first unread message

Arun Shriram

unread,
Jul 25, 2017, 5:16:15 PM7/25/17
to pyqtgraph
Hello!
I'm working on a project for a company I'm interning at, and in my window I'm including a PlotWidget that simply draws points connected by lines. I've set it up so that whenever the user holds their mouse over the graph, it will display the graph coordinates on a Label, as shown in the picture I've attached.

I'd like to include a way for the "setLogMode" to be turned on and off with a QCheckBox. However, when the user moves the mouse over the plot with the log mode turned on, the number on the "y" label only shows the exponent value (the values are between 10^3 and 10^4, so it shows values like 3.245, 3.892, etc.), when I'd like it to show the real value instead. Here's the code for the mouse moved function (that works properly for non-log mode:

def mouseMoved(self, evt):
        pos = evt[0]  ## using signal proxy turns original arguments into a tuple
        if self.pw.sceneBoundingRect().contains(pos):
            mousePoint = self.vb.mapSceneToView(pos)
                      
            yPoint = "{:.4e}".format(mousePoint.y())

            self.graphcoordinates.setText("<span style='font-size: 12pt'>x = %0.4f, <span style='color: red'>y = %s</span>" % (mousePoint.x(), yPoint)) # This simply displays the mouse coordinates
                
            self.vLine.setPos(mousePoint.x()) #sets the position of the crosshair lines
            self.hLine.setPos(mousePoint.y())  

Help with this would be greatly appreciated. I couldn't find anything online regarding this problem of mine. Thank you!

Arun

Screen Shot 2017-07-25 at 2.11.22 PM.png
Reply all
Reply to author
Forward
0 new messages