Python icons on matplotlib.image.AxesImage object

I have an object AxesImagein Python from pylab. How do I draw dots on top of the plot?

For example, I did imshowin the 2D array that I have, returning AxesImage. Then I found a few peaks and found pairs (i, j)that match the peaks. Now all I have to do is overlay them on top of the image.

I think a function is scatter()usually the way you draw something like this (?), But I could not get its overlay.

Thanks!

+4
source share
1 answer

The solution was quite simple, but did not know that you can use Axes objects as follows:

import matplotlib.pyplot as plt

# detect peaks somehow
i, j = detect_peaks(array2d)

# plot
fig, ax = plt.subplots()
ax.imshow(array2d)
ax.scatter(i, j)
plt.show()

, matplotlib, .

+2

All Articles