简体   繁体   中英

How add scatter to plt.imshow

I write code for animation image, how i can add point on it?
(The code does not work in this form, I have simplified it as much as possible)

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation

files = os.listdir(r'..')
fig = plt.figure()
myimages = []

for i in files:
    frame = np.load(r'..\{}'.format(i))
    cmap = plt.cm.jet
    image = cmap(norm(ndimage.grey_closing(frame)))

    plt.scatter(point_arr[:, 1], point_arr[:, 0])  # Wanna add this in anim

    frame1 = plt.imshow(image, cmap=cmap)
    myimages.append([frame1 ])

my_anim = animation.ArtistAnimation(fig, myimages, interval=50, blit=True, repeat_delay=2000)
plt.show() # show but without my point

without anim all work, but how merge i dont know

frame1 = plt.imshow(frame2, cmap=cmap)
plt.scatter(point_arr[:, 1], point_arr[:, 0])
plt.show() # all work

Work

    plt.scatter(point_arr[:, 1], point_arr[:, 0], c='green')
    plt.imshow(image, cmap=plt.cm.jet)
    camera.snap()

animation = camera.animate(interval=50, blit=True, repeat_delay=2000)
animation.save('test.gif', writer='imagemagick')
print('End')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM