Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python plot peaks on matplotlib.image.AxesImage object

I have a an AxesImage object in Python from pylab. How do I plot points on top of the plot?

For example, I did imshow on a 2D array that I have, returning the AxesImage. Then I didn some peak finding and found (i, j) pairs which correspond to the peaks. Now all I have to do is overlay them on top of the image.

I think the scatter() function is normally how you plot something like this (?) but I couldn't get it to overlay.

Thanks!

like image 374
lollercoaster Avatar asked Oct 21 '22 21:10

lollercoaster


1 Answers

Solution was fairly simple, but wasn't aware you could use Axes objects like this:

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()

Probably very simple for most matplotlib experts, but took quite a bit of guesswork on my part.

like image 109
lollercoaster Avatar answered Oct 24 '22 03:10

lollercoaster