Python在图像上绘制动画

2024-06-10 05:52:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我想为每个新位置连续画出点i,同时清除之前的帧以可视化移动。我走对了吗?我习惯于使用setinterval函数在Javascript中对其进行编码,但我对Python是新手

fig = plt.figure(1)
    ax  = fig.add_subplot(111)
    ax.imshow(img, cmap=plt.cm.gray)
    ax.set_xticks([])
    ax.set_yticks([])
    ax.set_xlim(0,img.shape[1])
    ax.plot(np.r_[x,x[0]], np.r_[y,y[0]], c=(0.5,0.5,0.5), lw=1)

    for i, snake in enumerate(snakePoints):
        if i % 15 == 0:
            ax.plot(np.r_[snake[0], snake[0][0]], np.r_[snake[1], snake[1][0]], c=(0.1,0,1,0.3), lw=1)


    ax.plot(np.r_[snakePoints[-1][0], snakePoints[-1][0][0]], np.r_[snakePoints[-1][1], snakePoints[-1][1][0]], c=(1,0,0), lw=3)
    plt.show()

Tags: 函数imgplot可视化npfigpltjavascript
1条回答
网友
1楼 · 发布于 2024-06-10 05:52:02

试试下面的用法

ax.clear() # to clear the previous output

plt.pause(0.001) # to pause and show animation for new plot 

并编写一个函数来调用新的参数和绘图。我想你的压痕是错的

相关问题 更多 >