'Detect aligned point in a scatter plot

I'm looking to write a script that does automatic detection of vertically or horizontally aligned points as shown in the image below.

thank you in advance for your help.

image



Sources

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

Source: Stack Overflow

Solution Source