[mpl_point_clicker] allow the user to select only 1 point per class

Hi there!

I’m pretty new here, so please don’t be mad at me!

I’m doing some data analysis and for this purpose I would like to draw profiles of a lot of images. More in the details, this is what I’m doing:

  1. load the image
  2. find the contour of the image
  3. get a point on the contour
  4. draw a straight line perpendicular to the contour in that point
  5. get the profile of the image along that straight line.

Up to here, everything is fine and perfectly working. What I would like to implement next is a simple user interaction.
In the specific: at the moment the straight line along which the profile is calculated, is crossing the whole image, but I would like to give the possibility to the user to limit the range of this line between two points. For this reason, I would like the user to select a starting point and ending point simply clicking on the graph, and I thought this would be the perfect application for the mpl_point_clicker.

I was thinking to use two classes (beginning and end), but I want the user to be able to add only one beginning and one end marker. When a second one is added, the first one is removed.

Another point, I doing this with plt.ion() and I don’t know how to make the code execution to wait for both markers to be selected and eventually ask the user for a confirmation about the selection.

Can you help me with this problem?


Hi toto,

I’m pretty new here, so please don’t be mad at me!

no one here will be mad at you for asking questions :slight_smile:

If I correctly understand what you’re trying to do I actually think that this library: mpl-draggable-line’s Documentation — mpl-draggable-line is much closer to what you want. Does that look like it might be on the right track?