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!

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Please see stackoverflow.com/questions/14254379/…. This is what pyplot is doing underneath for you anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.