5

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!

lollercoaster
  • 15,969
  • 35
  • 115
  • 173

1 Answers1

3

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.

lollercoaster
  • 15,969
  • 35
  • 115
  • 173
  • Please see http://stackoverflow.com/questions/14254379/how-can-i-attach-a-pyplot-function-to-a-figure-instance/14261698#14261698. This is what pyplot is doing underneath for you anyway. – tacaswell Nov 03 '13 at 23:39