I am using this example code as my starting code
This code generates a bar graph. When the user clicks on an actual bar on the bar graph, an event is triggered and the bounding box coordinates of the individual bar are displayed. This happens in the on_pick function.
I have modified the code so instead of a bar graph, I have a Axes3D line plot. I have several separate lines plotted on this XYZ coordinate system. What I need is to recognize which line was clicked. It appears that the bounding box does not work for the 3D plot as it did with the bar graph.
I have looked into the pick_event documentation but have been unsuccessful in finding a solution. I can simply detect the x,y coordinate of the location clicked, but because the plot can be rotated at any angle, it seems quite difficult to detect which line was actually clicked, especially since they can be overlapping depending on the point of view.
I appreciate your time and help!
If you only need to know which curve is clicked, it’s not very difficult. You need to create a line_picker() to check whether the mouse position is close enough to the curve or not.
line_picker() need to calculate distance between point and line segments, that’s a little difficult, I walk around this problem by using linear interpolation of the curve.
Here is the code, I interpolate the curve by 2000 points, and if the mouse position to the curve is less than 5 pixels, then the curve is selected.