您无需一直打来电话
imshow。使用对象的
set_data方法要快得多:
myobj = imshow(first_image)for pixel in pixels: addpixel(pixel) myobj.set_data(segmentedimg) draw()
本
draw()应确保后端更新图像。
更新: 您的问题已被重大修改。在这种情况下,最好再问一个问题。这是解决第二个问题的方法:
Matplotlib的动画仅处理一个增加的维度(时间),因此您的双循环不会执行。您需要将索引转换为单个索引。这是一个例子:
import numpy as npfrom matplotlib import pyplot as pltfrom matplotlib import animationnx = 150ny = 50fig = plt.figure()data = np.zeros((nx, ny))im = plt.imshow(data, cmap='gist_gray_r', vmin=0, vmax=1)def init(): im.set_data(np.zeros((nx, ny)))def animate(i): xi = i // ny yi = i % ny data[xi, yi] = 1 im.set_data(data) return imanim = animation.FuncAnimation(fig, animate, init_func=init, frames=nx * ny, interval=50)



