'Matplotlib interactive selection of a line segment

Bit of a general question here. I would like to write some code wherein I make a line plot using matplotlib (which I know how to do), however, I would like the user to be able to click on a segment of said line plot, and have the 2 points at the end of the line be output. Is this possible using matplotlib? If there are better ways to do this other than with matplotlib I am open to suggestions. Any ideas welcome.

Cheers



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source