【问题标题】:Continuously render numpy arrays in loop在循环中连续渲染 numpy 数组
【发布时间】:2018-05-01 17:36:30
【问题描述】:

我的代码在 while 循环中运行,并在每次迭代时返回一个新的 numpy 数组。我想将该数组连续渲染到屏幕窗口。

基于Displaying Numpy Matrix as VideoIs there a way to detach matplotlib plots so that the computation can continue?How to update matplotlib's imshow() window interactively?real-time plotting in while loop with matplotlib,这是我最好的尝试:

import matplotlib.pyplot as plt
import numpy as np

# plt.ion()
image = np.zeros((800, 800))
im = plt.imshow(image)
while True:
    image += .01
    im.set_data(image)
    plt.pause(0.05)
plt.show()

它不起作用(由于某种原因,它只是呈现一个不会改变颜色的紫色方块)。我在 Ubuntu 16.04 上使用 ImageMagick。感谢您的帮助。

【问题讨论】:

    标签: numpy matplotlib rendering


    【解决方案1】:

    简单修正:

    image = np.zeros((800, 800, 3))
    

    现在可以了。

    【讨论】:

      猜你喜欢
      • 2019-01-20
      • 2022-07-02
      • 2018-07-09
      • 2019-09-11
      • 1970-01-01
      • 2018-08-08
      • 2020-12-16
      • 2014-01-15
      相关资源
      最近更新 更多