我正在使用python腳本在對象Plotter中使用以下方法:import matplotlib.pyplot as pltclass Plotter: def __init__(self): self.nbfig = 0 def plot(self): self.nbfig += 1 plt.figure(self.nbfig) plt.plot(self.time, self.angle, 'b') plt.ion() plt.show()實時C ++應用程序在需要繪制某些內容時會調用python腳本(這就是為什么我使用plt.ion()以便繪圖在不同的線程中運行并且不會停止c ++應用程序)的原因,有時c ++應用程序需要刷新應用程序并調用以下方法:def refresh(self): if (self.nbfig > 0): #meaning the c++ app already plotted a figure plt.close()這種方法有效地關閉了我繪制角度的matplotlib窗口。但是,當它第二次調用方法圖(如上定義)時,不會繪制任何內容(出現一個空窗口)。似乎調用plt.close()會影響matplotlib的所有行為(我嘗試手動關閉窗口,并且腳本能夠一個接一個地繪制不同的圖)您是否遇到過此類問題?
關閉matplotlib中的第一個圖形后繪制新圖形
幕布斯6054654
2021-03-31 17:05:21