It takes some testing, but it might work? All must be in the display area.
def overlap(x, y, sx, sy): return np.linalg.norm(x - y) < np.linalg.norm(sx + sy)
Test:
In [227]: X = np.array([[1, 1], [2, 1], [2.5, 1]]) In [228]: s = np.array([20, 10000, 10000]) In [229]: fig, ax = plt.subplots() In [230]: ax.scatter(X[:, 0], X[:, 1], s=s) Out[230]: <matplotlib.collections.PathCollection at 0x10c32f28> In [231]: plt.draw()
Check each pair:
Xt = ax.transData.transform(X) st = np.sqrt(s) pairs = product(Xt, Xt) sizes = product(st, st) for i, ((x, y), (sx, sy)) in enumerate(zip(pairs, sizes)): h = i % 3 j = i // 3 if h != j and overlap(x, y, sx, sy): print((i, h, j))

There are many opportunities for improvement. It is probably easier to convert all of your data and pass it to the points_overlap function instead of doing the conversion inside. That would be much better.
Tomugspurger
source share