Hi Patrick, 

Thanks for taking the time to respond! Sorry I didn't reply sooner. I 
attempted to modify and implement your example, but I'm unable to get it to 
work properly: 

    def cursorLine(self):
        self.selected_x_i = 0
        self.selected_x = str(self.curvesData.get(0)[self.selected_x_i])

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

        self.crosshairx.setBounds(bounds=(0,len(self.curvesData.get(0))))

        # 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(len(self.curvesData.get(0)) - 
self.crosshairx.value()))

        self.plotItem.scene().addItem(self.crosshairx)


    def _crosshairx_changed(self):
        new_i = np.argmin(np.abs(len(self.curvesData.get(0)) - 
self.crosshairx.value()))
        if new_i != self.selected_x_i:
            self.selected_x_i = new_i
            self.selected_x = str(self.curvesData.get(0)[self.selected_x_i])
            print(self.curvesData(0)[self.selected_x_i])

Your emitting the setting of the label confused me a bit, but I understand 
the idea of the example in that you keep track of when the line is moved 
and thus change which X value you should be accessing. It seemed that there 
wasn't actually a connection between the line being moved and 
_crosshairx_changed() so I added the parenthesis after sigPositionChanged. 
This results in the error "TypeError: native Qt signal is not callable". 
Sorry about asking for help again, but I'm really not sure where to go from 
here. 

Kind Regards,

Jacob

On Friday, November 30, 2018 at 9:27:03 PM UTC-6, Patrick wrote:
>
> 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
>
> On Saturday, 1 December 2018 05:22:37 UTC+10:30, Jacob Bernard wrote:
>>
>> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/5341f4e4-9b7d-4bc6-b999-5393c7a97e05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to