Discussion:
[pyqtgraph] infliniteLine label value(s)
Jacob Bernard
2018-11-30 18:52:36 UTC
Permalink
I have an infiniteline on my graph, and have figured out how to use value
to get the value of the current axis:

infline = pg.InfiniteLine(pos=1000, movable=True, label='{value:0.2fms}')


However I would like to have my line vertically as it is now, but display
the y values of my curves. Is this possible? I know that if I make the line
horizontal it will give the y value, but I'd like for it to remain
vertical.
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/bdb352d2-4637-44b9-8d96-5b02a8de42fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Patrick
2018-12-01 03:27:03 UTC
Permalink
Hi,

You can connect to signals emitted by the infiniteline when it is moved.
Example code snippet below:


# Assume plot data is stored in arrays of xcoords, yvalues
self.xcoords = np.linspace(0.1, 10, 10)
self.yvalues = np.log(self.xcoords)


# Create the infinite line to select an x coordinate, connect to its moved
signal
self.crosshairx = pg.InfiniteLine(angle=90, movable=True)
self.crosshairx.sigPositionChanged.connect(self._crosshairx_changed)


# Keep track of index of currently selected x coordinate, so we can avoid
doing
# unnecessary updates when the infiniteline changes but the index of the
# closest x/y data point is still the same
self.selected_x_i = np.argmin(np.abs(self.xcoords - self.crosshairx.value
()))


# Slot to get y value of point closest to x value of the infinite line
def _crosshairx_changed(self):
new_i = np.argmin(np.abs(self.xcoords - self.crosshairx.value()))
if new_i != self.selected_x_i:
self.selected_x_i = new_i
# Do something interesting
print(self.yvalues[self.selected_x_i])


Patrick
Post by Jacob Bernard
I have an infiniteline on my graph, and have figured out how to use value
infline = pg.InfiniteLine(pos=1000, movable=True, label='{value:0.2fms}')
However I would like to have my line vertically as it is now, but display
the y values of my curves. Is this possible? I know that if I make the line
horizontal it will give the y value, but I'd like for it to remain
vertical.
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/f9728e66-2a5d-4ed2-98bc-4e845a919abd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...