0

Using this SO post, I can plot images instead of points:

def _implot(self, x, y, image, ax, zoom=1):
    im = OffsetImage(image, zoom=zoom, cmap='gray_r')
    ab = AnnotationBbox(im, (x, y), xycoords='data', frameon=False)
    ax.add_artist(ab)
    ax.update_datalim(np.column_stack([x, y]))
    ax.autoscale()

fig, ax = plt.subplots(1, 1)
fig.set_size_inches(10, 10)
for img, x in zip(Y, X):
    img = img.reshape(28, 28)
    self._implot(x[0], x[1], img, ax=ax, zoom=0.5)

Above, Y is an Nx(28*28) matrix of flattened images and X is an Nx2 matrix of locations. My issue is that many of these images overlap, making the figure hard to read:

MNIST with overlapping images

I'd like to skip plotting any image if it would overlap with an existing image. How can I do this? I could manually track which (x, y) coordinates have been plotted and also account for the image width and height, but that seems brittle, and I'm hoping Matplotlib has a built-in way to check for overlapping artists.

jds
  • 7,910
  • 11
  • 63
  • 101
  • Maybe one should note that in a case where each image overlaps with a previous one, such algorithm would lead to only one single image being shown. – ImportanceOfBeingErnest Mar 02 '20 at 14:06
  • The only pathological case I can think of is if all images overlap jointly. If the i-th image overlaps with the (i-1)-th image, it will not be added. Thus, it does not matter if the (i+1)-th image overlaps with the i-th image provided it doesn't also overlap with the (i-1)-th image. See Figure 3 here for an example: https://papers.nips.cc/paper/2540-gaussian-process-latent-variable-models-for-visualisation-of-high-dimensional-data.pdf – jds Mar 02 '20 at 14:17

0 Answers0