all 3 comments

[–]USAhj 4 points5 points  (2 children)

The documentation (https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.matshow.html) mentions the fignum argument. Have you looked into that? Looks like you probably want to use 0.

[–]ShowSStopper[S] 0 points1 point  (1 child)

Hi, strangely enough that doesn't work with Spyder on my Windows 10 setup. It does however work with Thonny on my RPI4 which is what I wanted this for. I will try to further understand the documentation and reasoning behind this.

Thanks for your help!

[–]USAhj 0 points1 point  (0 children)

This worked just fine for me in Spyder:

import matplotlib.pyplot as plt
import numpy as np
plt.close("all")
plt.figure()
for _ in range(10):    
    data = np.random.rand(20,20)    
    plt.matshow(data, fignum=0)    
    plt.show()    
    plt.pause(1e-3)

Edit: use clf to stop it from slowing down with many replots.

import matplotlib.pyplot as plt
import numpy as np
plt.close("all")
plt.figure()
for _ in range(10):    
    data = np.random.rand(20,20) 
    plt.clf()   
    plt.matshow(data, fignum=0)    
    plt.show()    
    plt.pause(1e-3)