我正在使用python腳本在對(duì)象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()實(shí)時(shí)C ++應(yīng)用程序在需要繪制某些內(nèi)容時(shí)會(huì)調(diào)用python腳本(這就是為什么我使用plt.ion()以便繪圖在不同的線程中運(yùn)行并且不會(huì)停止c ++應(yīng)用程序)的原因,有時(shí)c ++應(yīng)用程序需要刷新應(yīng)用程序并調(diào)用以下方法:def refresh(self): if (self.nbfig > 0): #meaning the c++ app already plotted a figure plt.close()這種方法有效地關(guān)閉了我繪制角度的matplotlib窗口。但是,當(dāng)它第二次調(diào)用方法圖(如上定義)時(shí),不會(huì)繪制任何內(nèi)容(出現(xiàn)一個(gè)空窗口)。似乎調(diào)用plt.close()會(huì)影響matplotlib的所有行為(我嘗試手動(dòng)關(guān)閉窗口,并且腳本能夠一個(gè)接一個(gè)地繪制不同的圖)您是否遇到過(guò)此類(lèi)問(wèn)題?
關(guān)閉matplotlib中的第一個(gè)圖形后繪制新圖形
幕布斯6054654
2021-03-31 17:05:21