Continuously render numpy arrays in loop

I have code that runs in a while loop and returns a new numpy array on every iteration. I would like to continuously render that array to an onscreen window.

Based on Displaying Numpy Matrix as Video, Is there a way to detach matplotlib plots so that the computation can continue?, How to update matplotlib's imshow() window interactively?, and real-time plotting in while loop with matplotlib, this is my best attempt:

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()

It does not work (for some reason it just renders a purple square that does not change color). I am using ImageMagick on Ubuntu 16.04. Thank you for your assistance.


Simple correction:

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

Now it works.

链接地址: http://www.djcxy.com/p/48374.html

上一篇: 在JavaScript中解析JSON?

下一篇: 循环中连续渲染numpy数组